Merge pull request #3 from SimonIT/null-safety

Migrate to null-safety
This commit is contained in:
reidha 2021-10-23 10:19:26 +08:00 committed by GitHub
commit 9addbfa755
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 182 deletions

View file

@ -42,11 +42,11 @@ Widget createScaffold() {
children: <Widget>[ children: <Widget>[
CheckboxListTileFormField( CheckboxListTileFormField(
title: Text('Check!'), title: Text('Check!'),
onSaved: (bool value) { onSaved: (bool? value) {
print(value); print(value);
}, },
validator: (bool value) { validator: (bool? value) {
if (value) { if (value!) {
return null; return null;
} else { } else {
return 'False!'; return 'False!';
@ -57,12 +57,12 @@ Widget createScaffold() {
initialValue: true, initialValue: true,
enabled: false, enabled: false,
iconSize: 32, iconSize: 32,
onSaved: (bool value) {}, onSaved: (bool? value) {},
), ),
RaisedButton( RaisedButton(
onPressed: () { onPressed: () {
if (_formKey.currentState.validate()) { if (_formKey.currentState!.validate()) {
_formKey.currentState.save(); _formKey.currentState!.save();
} }
}, },
child: Text('New'), child: Text('New'),

View file

@ -1,41 +1,34 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: 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: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.0" version: "2.6.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted 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: charcode:
dependency: transitive dependency: transitive
description: description:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.2" version: "1.2.0"
checkbox_formfield: checkbox_formfield:
dependency: "direct main" dependency: "direct main"
description: description:
@ -43,27 +36,20 @@ packages:
relative: true relative: true
source: path source: path
version: "0.1.0+3" version: "0.1.0+3"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.11" version: "1.15.0"
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"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -71,6 +57,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -81,55 +74,27 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.6" version: "0.12.10"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.4" version: "1.8.0"
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"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -141,62 +106,55 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.5" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.9.3" version: "1.10.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.1.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.11" version: "0.3.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks: sdks:
dart: ">=2.4.0 <3.0.0" dart: ">=2.12.0 <3.0.0"

View file

@ -14,7 +14,7 @@ description: checkbox_formfield example
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
flutter: flutter:

View file

@ -3,19 +3,19 @@ import 'package:flutter/material.dart';
/// Use Icon as checkbox /// Use Icon as checkbox
class CheckboxIconFormField extends FormField<bool> { class CheckboxIconFormField extends FormField<bool> {
CheckboxIconFormField({ CheckboxIconFormField({
Key key, Key? key,
BuildContext context, BuildContext? context,
FormFieldSetter<bool> onSaved, FormFieldSetter<bool>? onSaved,
bool initialValue = false, bool initialValue = false,
bool autovalidate = false, bool autovalidate = false,
bool enabled = true, bool enabled = true,
IconData trueIcon = Icons.check, IconData trueIcon = Icons.check,
IconData falseIcon = Icons.check_box_outline_blank, IconData falseIcon = Icons.check_box_outline_blank,
Color trueIconColor, Color? trueIconColor,
Color falseIconColor, Color? falseIconColor,
Color disabledColor, Color? disabledColor,
double padding = 24.0, double padding = 24.0,
double iconSize, double? iconSize,
}) : super( }) : super(
key: key, key: key,
onSaved: onSaved, onSaved: onSaved,
@ -28,7 +28,7 @@ class CheckboxIconFormField extends FormField<bool> {
return Padding( return Padding(
padding: EdgeInsets.all(padding), padding: EdgeInsets.all(padding),
child: state.value child: state.value!
? _createTappableIcon(state, enabled, trueIcon, ? _createTappableIcon(state, enabled, trueIcon,
trueIconColor, disabledColor, iconSize) trueIconColor, disabledColor, iconSize)
: _createTappableIcon(state, enabled, falseIcon, : _createTappableIcon(state, enabled, falseIcon,
@ -37,11 +37,11 @@ class CheckboxIconFormField extends FormField<bool> {
); );
static Widget _createTappableIcon(FormFieldState<bool> state, bool enabled, static Widget _createTappableIcon(FormFieldState<bool> state, bool enabled,
IconData icon, Color iconColor, Color disabledColor, double iconSize) { IconData icon, Color? iconColor, Color? disabledColor, double? iconSize) {
return IconButton( return IconButton(
onPressed: enabled onPressed: enabled
? () { ? () {
state.didChange(!state.value); state.didChange(!state.value!);
} }
: null, : null,
icon: Icon(icon, icon: Icon(icon,

View file

@ -3,20 +3,20 @@ import 'package:flutter/material.dart';
/// Use CheckboxListTile as part of Form /// Use CheckboxListTile as part of Form
class CheckboxListTileFormField extends FormField<bool> { class CheckboxListTileFormField extends FormField<bool> {
CheckboxListTileFormField({ CheckboxListTileFormField({
Key key, Key? key,
Widget title, Widget? title,
BuildContext context, BuildContext? context,
FormFieldSetter<bool> onSaved, FormFieldSetter<bool>? onSaved,
FormFieldValidator<bool> validator, FormFieldValidator<bool>? validator,
bool initialValue = false, bool initialValue = false,
bool autovalidate = false, bool autovalidate = false,
bool enabled = true, bool enabled = true,
bool dense = false, bool dense = false,
Color errorColor, Color? errorColor,
Color activeColor, Color? activeColor,
Color checkColor, Color? checkColor,
ListTileControlAffinity controlAffinity = ListTileControlAffinity.leading, ListTileControlAffinity controlAffinity = ListTileControlAffinity.leading,
Widget secondary, Widget? secondary,
}) : super( }) : super(
key: key, key: key,
onSaved: onSaved, onSaved: onSaved,
@ -36,7 +36,7 @@ class CheckboxListTileFormField extends FormField<bool> {
onChanged: enabled ? state.didChange : null, onChanged: enabled ? state.didChange : null,
subtitle: state.hasError subtitle: state.hasError
? Text( ? Text(
state.errorText, state.errorText!,
style: TextStyle(color: errorColor), style: TextStyle(color: errorColor),
) )
: null, : null,

View file

@ -1,62 +1,55 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: 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: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.0" version: "2.6.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted 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: charcode:
dependency: transitive dependency: transitive
description: description:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted 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: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.11" version: "1.15.0"
convert: fake_async:
dependency: transitive dependency: transitive
description: description:
name: convert name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "1.2.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -67,55 +60,27 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.6" version: "0.12.10"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.4" version: "1.8.0"
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"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -127,62 +92,55 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.5" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.9.3" version: "1.10.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.1.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.11" version: "0.3.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks: sdks:
dart: ">=2.4.0 <3.0.0" dart: ">=2.12.0 <3.0.0"

View file

@ -5,7 +5,7 @@ homepage: https://reidha.github.io/
repository: https://github.com/reidha/checkbox_formfield repository: https://github.com/reidha/checkbox_formfield
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
flutter: flutter: