From 106f2d6bbbfe6dcae28e87f41d9d39e775a4a6a7 Mon Sep 17 00:00:00 2001 From: SimonIT Date: Tue, 17 Aug 2021 13:48:08 +0200 Subject: [PATCH] Migrate to null-safety fixes #1 --- example/lib/main.dart | 12 +-- example/pubspec.lock | 116 ++++++++------------------ example/pubspec.yaml | 2 +- lib/checkbox_icon_formfield.dart | 20 ++--- lib/checkbox_list_tile_formfield.dart | 20 ++--- pubspec.lock | 108 ++++++++---------------- pubspec.yaml | 2 +- 7 files changed, 98 insertions(+), 182 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 7cb98a4..1723978 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,11 +42,11 @@ Widget createScaffold() { children: [ CheckboxListTileFormField( title: Text('Check!'), - onSaved: (bool value) { + onSaved: (bool? value) { print(value); }, - validator: (bool value) { - if (value) { + validator: (bool? value) { + if (value!) { return null; } else { return 'False!'; @@ -57,12 +57,12 @@ Widget createScaffold() { initialValue: true, enabled: false, iconSize: 32, - onSaved: (bool value) {}, + onSaved: (bool? value) {}, ), RaisedButton( onPressed: () { - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); + if (_formKey.currentState!.validate()) { + _formKey.currentState!.save(); } }, child: Text('New'), diff --git a/example/pubspec.lock b/example/pubspec.lock index 5a3ae0f..3ec17cf 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,41 +1,34 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" checkbox_formfield: dependency: "direct main" description: @@ -43,27 +36,20 @@ packages: relative: true source: path version: "0.1.0+3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -71,6 +57,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -81,55 +74,27 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -141,62 +106,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1708e55..10434e2 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,7 +14,7 @@ description: checkbox_formfield example version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: diff --git a/lib/checkbox_icon_formfield.dart b/lib/checkbox_icon_formfield.dart index 0e87ea7..3b2e68f 100644 --- a/lib/checkbox_icon_formfield.dart +++ b/lib/checkbox_icon_formfield.dart @@ -3,19 +3,19 @@ import 'package:flutter/material.dart'; /// Use Icon as checkbox class CheckboxIconFormField extends FormField { CheckboxIconFormField({ - Key key, - BuildContext context, - FormFieldSetter onSaved, + Key? key, + BuildContext? context, + FormFieldSetter? onSaved, bool initialValue = false, bool autovalidate = false, bool enabled = true, IconData trueIcon = Icons.check, IconData falseIcon = Icons.check_box_outline_blank, - Color trueIconColor, - Color falseIconColor, - Color disabledColor, + Color? trueIconColor, + Color? falseIconColor, + Color? disabledColor, double padding = 24.0, - double iconSize, + double? iconSize, }) : super( key: key, onSaved: onSaved, @@ -28,7 +28,7 @@ class CheckboxIconFormField extends FormField { return Padding( padding: EdgeInsets.all(padding), - child: state.value + child: state.value! ? _createTappableIcon(state, enabled, trueIcon, trueIconColor, disabledColor, iconSize) : _createTappableIcon(state, enabled, falseIcon, @@ -37,11 +37,11 @@ class CheckboxIconFormField extends FormField { ); static Widget _createTappableIcon(FormFieldState state, bool enabled, - IconData icon, Color iconColor, Color disabledColor, double iconSize) { + IconData icon, Color? iconColor, Color? disabledColor, double? iconSize) { return IconButton( onPressed: enabled ? () { - state.didChange(!state.value); + state.didChange(!state.value!); } : null, icon: Icon(icon, diff --git a/lib/checkbox_list_tile_formfield.dart b/lib/checkbox_list_tile_formfield.dart index 90060d8..4facd5d 100644 --- a/lib/checkbox_list_tile_formfield.dart +++ b/lib/checkbox_list_tile_formfield.dart @@ -3,20 +3,20 @@ import 'package:flutter/material.dart'; /// Use CheckboxListTile as part of Form class CheckboxListTileFormField extends FormField { CheckboxListTileFormField({ - Key key, - Widget title, - BuildContext context, - FormFieldSetter onSaved, - FormFieldValidator validator, + Key? key, + Widget? title, + BuildContext? context, + FormFieldSetter? onSaved, + FormFieldValidator? validator, bool initialValue = false, bool autovalidate = false, bool enabled = true, bool dense = false, - Color errorColor, - Color activeColor, - Color checkColor, + Color? errorColor, + Color? activeColor, + Color? checkColor, ListTileControlAffinity controlAffinity = ListTileControlAffinity.leading, - Widget secondary, + Widget? secondary, }) : super( key: key, onSaved: onSaved, @@ -36,7 +36,7 @@ class CheckboxListTileFormField extends FormField { onChanged: enabled ? state.didChange : null, subtitle: state.hasError ? Text( - state.errorText, + state.errorText!, style: TextStyle(color: errorColor), ) : null, diff --git a/pubspec.lock b/pubspec.lock index 67a7df1..ad6d1df 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,55 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.15.0" + fake_async: dependency: transitive description: - name: convert + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,55 +60,27 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -127,62 +92,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index d396cbd..67f5a8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://reidha.github.io/ repository: https://github.com/reidha/checkbox_formfield environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: