Ver código fonte

232: migrate example to null safety (#236)

Luke Pighetti 4 anos atrás
pai
commit
d0a7efc175

+ 4 - 5
.github/workflows/dart.yml

@@ -2,9 +2,9 @@ name: build
 
 on:
   push:
-    branches: [ master ]
+    branches: [ main ]
   pull_request:
-    branches: [ master ]
+    branches: [ main ]
 
 jobs:
   test:
@@ -17,6 +17,5 @@ jobs:
           java-version: '12.x'
       - uses: subosito/flutter-action@v1
         with:
-          channel: beta
-      - run: flutter pub get
-      - run: flutter test
+          channel: stable
+      - run: make clean test

+ 21 - 0
Makefile

@@ -0,0 +1,21 @@
+.PHONY: setup clean format test distribute
+
+setup:
+	flutter channel stable
+	flutter upgrade
+	
+clean:
+	flutter clean
+	flutter pub get
+	cd example && flutter clean
+	cd example && flutter pub get
+
+test:
+	flutter test
+	flutter analyze
+	flutter format --dry-run --set-exit-if-changed lib test
+	cd example && flutter analyze
+	cd example && flutter format --dry-run --set-exit-if-changed lib
+
+distribute: setup clean test
+	flutter pub publish

+ 1 - 1
example/lib/components/demo/demo_message_component.dart

@@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
 
 class DemoMessageComponent extends StatelessWidget {
   DemoMessageComponent(
-      {@required this.message, this.color = const Color(0xFFFFFFFF)});
+      {required this.message, this.color = const Color(0xFFFFFFFF)});
 
   final String message;
   final Color color;

+ 2 - 2
example/lib/components/demo/demo_simple_component.dart

@@ -14,14 +14,14 @@ class DemoSimpleComponent extends StatelessWidget {
   DemoSimpleComponent(
       {String message = "Testing",
       Color color = const Color(0xFFFFFFFF),
-      String result})
+      String? result})
       : this.message = message,
         this.color = color,
         this.result = result;
 
   final String message;
   final Color color;
-  final String result;
+  final String? result;
 
   @override
   Widget build(BuildContext context) {

+ 1 - 1
example/lib/components/home/home_component.dart

@@ -187,7 +187,7 @@ class HomeComponentState extends State<HomeComponent> {
   void tappedMenuButton(BuildContext context, String key) {
     String message = "";
     String hexCode = "#FFFFFF";
-    String result;
+    String? result;
     TransitionType transitionType = TransitionType.native;
     if (key != "custom" && key != "function-call" && key != "fixed-trans") {
       if (key == "native") {

+ 1 - 1
example/lib/config/application.dart

@@ -9,5 +9,5 @@
 import 'package:fluro/fluro.dart';
 
 class Application {
-  static FluroRouter router;
+  static late final FluroRouter router;
 }

+ 13 - 12
example/lib/config/route_handlers.dart

@@ -14,28 +14,29 @@ import 'package:fluro/fluro.dart';
 import 'package:flutter/material.dart';
 
 var rootHandler = Handler(
-    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
+    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
   return HomeComponent();
 });
 
 var demoRouteHandler = Handler(
-    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
-  String message = params["message"]?.first;
-  String colorHex = params["color_hex"]?.first;
-  String result = params["result"]?.first;
+    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
+  String? message = params["message"]?.first;
+  String? colorHex = params["color_hex"]?.first;
+  String? result = params["result"]?.first;
   Color color = Color(0xFFFFFFFF);
   if (colorHex != null && colorHex.length > 0) {
     color = Color(ColorHelpers.fromHexString(colorHex));
   }
-  return DemoSimpleComponent(message: message, color: color, result: result);
+  return DemoSimpleComponent(
+      message: message ?? 'Testing', color: color, result: result);
 });
 
 var demoFunctionHandler = Handler(
     type: HandlerType.function,
-    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
-      String message = params["message"]?.first;
+    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
+      String? message = params["message"]?.first;
       showDialog(
-        context: context,
+        context: context!,
         builder: (context) {
           return AlertDialog(
             title: Text(
@@ -69,9 +70,9 @@ var demoFunctionHandler = Handler(
 ///
 /// `adb shell am start -W -a android.intent.action.VIEW -d "fluro://deeplink?path=/message&mesage=fluro%20rocks%21%21" com.theyakka.fluro`
 var deepLinkHandler = Handler(
-    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
-  String colorHex = params["color_hex"]?.first;
-  String result = params["result"]?.first;
+    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
+  String? colorHex = params["color_hex"]?.first;
+  String? result = params["result"]?.first;
   Color color = Color(0xFFFFFFFF);
   if (colorHex != null && colorHex.length > 0) {
     color = Color(ColorHelpers.fromHexString(colorHex));

+ 1 - 1
example/lib/config/routes.dart

@@ -19,7 +19,7 @@ class Routes {
 
   static void configureRoutes(FluroRouter router) {
     router.notFoundHandler = Handler(
-        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
+        handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
       print("ROUTE WAS NOT FOUND !!!");
       return;
     });

+ 4 - 4
example/pubspec.lock

@@ -7,7 +7,7 @@ packages:
       name: async
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.5.0"
+    version: "2.6.1"
   boolean_selector:
     dependency: transitive
     description:
@@ -106,7 +106,7 @@ packages:
       name: source_span
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.8.0"
+    version: "1.8.1"
   stack_trace:
     dependency: transitive
     description:
@@ -141,7 +141,7 @@ packages:
       name: test_api
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.2.19"
+    version: "0.3.0"
   typed_data:
     dependency: transitive
     description:
@@ -157,5 +157,5 @@ packages:
     source: hosted
     version: "2.1.0"
 sdks:
-  dart: ">=2.12.0-0.0 <3.0.0"
+  dart: ">=2.12.0 <3.0.0"
   flutter: ">=1.17.0"

+ 1 - 1
example/pubspec.yaml

@@ -4,7 +4,7 @@ publish_to: "none"
 version: 1.0.0+1
 
 environment:
-  sdk: ">=2.7.0 <3.0.0"
+  sdk: ">=2.12.0 <3.0.0"
 
 dependencies:
   flutter:

+ 4 - 4
pubspec.lock

@@ -7,7 +7,7 @@ packages:
       name: async
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.5.0"
+    version: "2.6.1"
   boolean_selector:
     dependency: transitive
     description:
@@ -92,7 +92,7 @@ packages:
       name: source_span
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.8.0"
+    version: "1.8.1"
   stack_trace:
     dependency: transitive
     description:
@@ -127,7 +127,7 @@ packages:
       name: test_api
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.2.19"
+    version: "0.3.0"
   typed_data:
     dependency: transitive
     description:
@@ -143,5 +143,5 @@ packages:
     source: hosted
     version: "2.1.0"
 sdks:
-  dart: ">=2.12.0-0.0 <3.0.0"
+  dart: ">=2.12.0 <3.0.0"
   flutter: ">=1.17.0"