From bdf444f0e5f3065b1b27aacfd580eb5697713046 Mon Sep 17 00:00:00 2001 From: Tino Date: Sun, 25 Jun 2023 15:26:52 +0800 Subject: [PATCH] [FEAT] Adapt to dart3 --- analysis_options.yaml | 1 - example/.metadata | 26 ++++++++++++-- example/lib/main.dart | 84 +++++++++++++++++++++---------------------- example/pubspec.yaml | 4 +-- pubspec.yaml | 2 +- 5 files changed, 68 insertions(+), 49 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index a4dd3ac..b2213e6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,7 +2,6 @@ include: package:flutter_lints/flutter.yaml linter: rules: - - prefer_equal_for_default_values - prefer_generic_function_type_aliases - slash_for_doc_comments - unawaited_futures diff --git a/example/.metadata b/example/.metadata index 68702b9..53830e3 100644 --- a/example/.metadata +++ b/example/.metadata @@ -1,10 +1,30 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: d8d36bc7e84a63623cb9a92f2b2d6b243b3b743e - channel: master + revision: 796c8ef79279f9c774545b3771238c3098dbefab + channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + - platform: macos + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/lib/main.dart b/example/lib/main.dart index 8ebd8ca..5151ee2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,7 +52,7 @@ class ListPage extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage(this.textFieldType, {Key key}) : super(key: key); + MyHomePage(this.textFieldType, {Key? key}) : super(key: key); final TextFieldType textFieldType; @@ -75,24 +75,24 @@ class _MyHomePageState extends State { GlobalKey(debugLabel: 'home page global key'); /// Decorate the outside of the Pin. - PinDecoration _pinDecoration; + PinDecoration? _pinDecoration; /// Control whether show the obscureCode. - bool _obscureEnable = false; + bool? _obscureEnable = false; PinEntryType _pinEntryType = PinEntryType.underline; ColorBuilder _solidColor = - PinListenColorBuilder(Colors.grey, Colors.grey[400]); - bool _solidEnable = false; + PinListenColorBuilder(Colors.grey, Colors.grey[400]!); + bool? _solidEnable = false; /// Control whether textField is enable. - bool _enable = true; + bool? _enable = true; /// Indicate whether the PinInputTextFormField has error or not /// after being validated. bool _hasError = false; - bool _cursorEnable = true; + bool? _cursorEnable = true; Orientation _orientation = Orientation.vertical; @@ -125,9 +125,9 @@ class _MyHomePageState extends State { setState(() { _pinDecoration = UnderlineDecoration( colorBuilder: PinListenColorBuilder(Colors.cyan, Colors.green), - bgColorBuilder: _solidEnable ? _solidColor : null, + bgColorBuilder: _solidEnable! ? _solidColor : null, obscureStyle: ObscureStyle( - isTextObscure: _obscureEnable, + isTextObscure: _obscureEnable!, obscureText: '😂', ), ); @@ -136,9 +136,9 @@ class _MyHomePageState extends State { case PinEntryType.boxTight: setState(() { _pinDecoration = BoxTightDecoration( - bgColorBuilder: _solidEnable ? _solidColor : null, + bgColorBuilder: _solidEnable! ? _solidColor : null, obscureStyle: ObscureStyle( - isTextObscure: _obscureEnable, + isTextObscure: _obscureEnable!, obscureText: '👿', ), ); @@ -149,9 +149,9 @@ class _MyHomePageState extends State { _pinDecoration = BoxLooseDecoration( strokeColorBuilder: PinListenColorBuilder(Colors.cyan, Colors.green), - bgColorBuilder: _solidEnable ? _solidColor : null, + bgColorBuilder: _solidEnable! ? _solidColor : null, obscureStyle: ObscureStyle( - isTextObscure: _obscureEnable, + isTextObscure: _obscureEnable!, obscureText: '☺️', ), ); @@ -160,11 +160,11 @@ class _MyHomePageState extends State { case PinEntryType.circle: setState(() { _pinDecoration = CirclePinDecoration( - bgColorBuilder: _solidEnable ? _solidColor : null, + bgColorBuilder: _solidEnable! ? _solidColor : null, strokeColorBuilder: PinListenColorBuilder(Colors.cyan, Colors.green), obscureStyle: ObscureStyle( - isTextObscure: _obscureEnable, + isTextObscure: _obscureEnable!, obscureText: '🤪', ), ); @@ -308,10 +308,10 @@ class _MyHomePageState extends State { height: _kInputHeight, child: PinInputTextField( pinLength: _pinLength, - decoration: _pinDecoration, + decoration: _pinDecoration!, controller: _pinEditingController, textInputAction: TextInputAction.go, - enabled: _enable, + enabled: _enable!, keyboardType: TextInputType.text, textCapitalization: TextCapitalization.characters, onSubmit: (pin) { @@ -336,7 +336,7 @@ class _MyHomePageState extends State { width: 2, color: Colors.lightBlue, radius: Radius.circular(1), - enabled: _cursorEnable, + enabled: _cursorEnable!, orientation: Orientation.vertical, ); } @@ -348,7 +348,7 @@ class _MyHomePageState extends State { offset: 16, color: Colors.lightBlue, radius: Radius.circular(1), - enabled: _cursorEnable, + enabled: _cursorEnable!, orientation: Orientation.horizontal, ); } @@ -365,15 +365,15 @@ class _MyHomePageState extends State { child: PinInputTextFormField( key: _formKey, pinLength: _pinLength, - decoration: _pinDecoration, + decoration: _pinDecoration!, controller: _pinEditingController, textInputAction: TextInputAction.go, - enabled: _enable, + enabled: _enable!, keyboardType: TextInputType.text, textCapitalization: TextCapitalization.characters, onSubmit: (pin) { - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); + if (_formKey.currentState?.validate() == true) { + _formKey.currentState?.save(); } }, onChanged: (pin) { @@ -383,13 +383,13 @@ class _MyHomePageState extends State { debugPrint('onSaved pin:$pin'); }, validator: (pin) { - if (pin.isEmpty) { + if (pin?.isEmpty == true) { setState(() { _hasError = true; }); return 'Pin cannot empty.'; } - if (pin.length < _pinLength) { + if (pin!.length < _pinLength) { setState(() { _hasError = true; }); @@ -411,8 +411,8 @@ class _MyHomePageState extends State { children: [ ElevatedButton( onPressed: () { - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); + if (_formKey.currentState?.validate() == true) { + _formKey.currentState?.save(); } }, child: Text( @@ -471,13 +471,13 @@ class _MyHomePageState extends State { class ExampleDecoration extends PinDecoration { ExampleDecoration({ - TextStyle textStyle, - ObscureStyle obscureStyle, - String errorText, - TextStyle errorTextStyle, - String hintText, - TextStyle hintTextStyle, - ColorBuilder bgColorBuilder, + TextStyle? textStyle, + ObscureStyle? obscureStyle, + String? errorText, + TextStyle? errorTextStyle, + String? hintText, + TextStyle? hintTextStyle, + ColorBuilder? bgColorBuilder, }) : super( textStyle: textStyle, obscureStyle: obscureStyle, @@ -489,13 +489,13 @@ class ExampleDecoration extends PinDecoration { @override PinDecoration copyWith({ - TextStyle textStyle, - ObscureStyle obscureStyle, - String errorText, - TextStyle errorTextStyle, - String hintText, - TextStyle hintTextStyle, - ColorBuilder bgColorBuilder, + TextStyle? textStyle, + ObscureStyle? obscureStyle, + String? errorText, + TextStyle? errorTextStyle, + String? hintText, + TextStyle? hintTextStyle, + ColorBuilder? bgColorBuilder, }) { return ExampleDecoration( textStyle: textStyle ?? this.textStyle, @@ -516,7 +516,7 @@ class ExampleDecoration extends PinDecoration { Size size, String text, int pinLength, - Cursor cursor, + Cursor? cursor, TextDirection textDirection, ) { /// You can draw anything you want here. diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 18e4684..4f73297 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,7 +11,7 @@ publish_to: none version: 1.0.0+1 environment: - sdk: ">=2.2.2 <3.0.0" + sdk: ">=2.15.0 <3.0.0" dependencies: flutter: @@ -21,7 +21,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.5 dev_dependencies: flutter_test: diff --git a/pubspec.yaml b/pubspec.yaml index 0b60d00..d6c955e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/TinoGuo/pin_input_text_field issue_tracker: https://github.com/TinoGuo/pin_input_text_field/issues environment: - sdk: '>=2.13.0 <3.0.0' + sdk: '>=2.13.0 <4.0.0' flutter: ">=3.7.0" dependencies: