Skip to content

Commit

Permalink
[FEAT] Adapt to dart3
Browse files Browse the repository at this point in the history
  • Loading branch information
TinoGuo committed Jun 25, 2023
1 parent d51bb12 commit bdf444f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 49 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -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'
84 changes: 42 additions & 42 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -75,24 +75,24 @@ class _MyHomePageState extends State<MyHomePage> {
GlobalKey<ScaffoldState>(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;

Expand Down Expand Up @@ -125,9 +125,9 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() {
_pinDecoration = UnderlineDecoration(
colorBuilder: PinListenColorBuilder(Colors.cyan, Colors.green),
bgColorBuilder: _solidEnable ? _solidColor : null,
bgColorBuilder: _solidEnable! ? _solidColor : null,
obscureStyle: ObscureStyle(
isTextObscure: _obscureEnable,
isTextObscure: _obscureEnable!,
obscureText: '😂',
),
);
Expand All @@ -136,9 +136,9 @@ class _MyHomePageState extends State<MyHomePage> {
case PinEntryType.boxTight:
setState(() {
_pinDecoration = BoxTightDecoration(
bgColorBuilder: _solidEnable ? _solidColor : null,
bgColorBuilder: _solidEnable! ? _solidColor : null,
obscureStyle: ObscureStyle(
isTextObscure: _obscureEnable,
isTextObscure: _obscureEnable!,
obscureText: '👿',
),
);
Expand All @@ -149,9 +149,9 @@ class _MyHomePageState extends State<MyHomePage> {
_pinDecoration = BoxLooseDecoration(
strokeColorBuilder:
PinListenColorBuilder(Colors.cyan, Colors.green),
bgColorBuilder: _solidEnable ? _solidColor : null,
bgColorBuilder: _solidEnable! ? _solidColor : null,
obscureStyle: ObscureStyle(
isTextObscure: _obscureEnable,
isTextObscure: _obscureEnable!,
obscureText: '☺️',
),
);
Expand All @@ -160,11 +160,11 @@ class _MyHomePageState extends State<MyHomePage> {
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: '🤪',
),
);
Expand Down Expand Up @@ -308,10 +308,10 @@ class _MyHomePageState extends State<MyHomePage> {
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) {
Expand All @@ -336,7 +336,7 @@ class _MyHomePageState extends State<MyHomePage> {
width: 2,
color: Colors.lightBlue,
radius: Radius.circular(1),
enabled: _cursorEnable,
enabled: _cursorEnable!,
orientation: Orientation.vertical,
);
}
Expand All @@ -348,7 +348,7 @@ class _MyHomePageState extends State<MyHomePage> {
offset: 16,
color: Colors.lightBlue,
radius: Radius.circular(1),
enabled: _cursorEnable,
enabled: _cursorEnable!,
orientation: Orientation.horizontal,
);
}
Expand All @@ -365,15 +365,15 @@ class _MyHomePageState extends State<MyHomePage> {
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) {
Expand All @@ -383,13 +383,13 @@ class _MyHomePageState extends State<MyHomePage> {
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;
});
Expand All @@ -411,8 +411,8 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
ElevatedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
if (_formKey.currentState?.validate() == true) {
_formKey.currentState?.save();
}
},
child: Text(
Expand Down Expand Up @@ -471,13 +471,13 @@ class _MyHomePageState extends State<MyHomePage> {

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,
Expand All @@ -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,
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bdf444f

Please sign in to comment.