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>[
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'),

View file

@ -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"

View file

@ -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:

View file

@ -3,19 +3,19 @@ import 'package:flutter/material.dart';
/// Use Icon as checkbox
class CheckboxIconFormField extends FormField<bool> {
CheckboxIconFormField({
Key key,
BuildContext context,
FormFieldSetter<bool> onSaved,
Key? key,
BuildContext? context,
FormFieldSetter<bool>? 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<bool> {
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<bool> {
);
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(
onPressed: enabled
? () {
state.didChange(!state.value);
state.didChange(!state.value!);
}
: null,
icon: Icon(icon,

View file

@ -3,20 +3,20 @@ import 'package:flutter/material.dart';
/// Use CheckboxListTile as part of Form
class CheckboxListTileFormField extends FormField<bool> {
CheckboxListTileFormField({
Key key,
Widget title,
BuildContext context,
FormFieldSetter<bool> onSaved,
FormFieldValidator<bool> validator,
Key? key,
Widget? title,
BuildContext? context,
FormFieldSetter<bool>? onSaved,
FormFieldValidator<bool>? 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<bool> {
onChanged: enabled ? state.didChange : null,
subtitle: state.hasError
? Text(
state.errorText,
state.errorText!,
style: TextStyle(color: errorColor),
)
: null,

View file

@ -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"

View file

@ -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: