Skip to content

Commit

Permalink
Migrate null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-hwang committed Mar 13, 2021
1 parent 232330a commit cd462e3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 62 deletions.
71 changes: 33 additions & 38 deletions lib/outline_search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const double _kActionButtonDefaultSize = 36.0;
/// A widget that implements an outlined search bar.
class OutlineSearchBar extends StatefulWidget {
/// The keyword of [OutlineSearchBar] can be controlled with a [TextEditingController].
final TextEditingController textEditingController;
final TextEditingController? textEditingController;

/// Set the color of [OutlineSearchBar].
/// Default value is Color(0xFFFEFEFE)
final Color backgroundColor;
final Color? backgroundColor;

/// Set the border color of [OutlineSearchBar].
/// If value is null and theme brightness is light, use primaryColor, if dark, use accentColor.
final Color borderColor;
final Color? borderColor;

/// Set the border thickness of [OutlineSearchBar].
/// Default value is 1.0
Expand All @@ -44,32 +44,32 @@ class OutlineSearchBar extends StatefulWidget {

/// Set the keyword to be initially entered.
/// If initial text is set in [textEditingController], this value is ignored.
final String initText;
final String? initText;

/// Set the text to be displayed when the keyword is empty.
final String hintText;
final String? hintText;

/// Set the input text style.
final TextStyle textStyle;
final TextStyle? textStyle;

/// Set the style of [hintText].
final TextStyle hintStyle;
final TextStyle? hintStyle;

/// Set the maximum length of text to be entered.
final int maxLength;
final int? maxLength;

/// Set the color of cursor.
final Color cursorColor;
final Color? cursorColor;

/// Set the width of cursor.
/// Default value is 2.0
final double cursorWidth;

/// Set the height of cursor.
final double cursorHeight;
final double? cursorHeight;

/// Set the radius of cursor.
final Radius cursorRadius;
final Radius? cursorRadius;

/// Set the background color of the clear button.
/// Default value is Color(0xFFDDDDDD)
Expand All @@ -80,11 +80,11 @@ class OutlineSearchBar extends StatefulWidget {
final Color clearButtonIconColor;

/// Set the splash color that appears when the search button is pressed.
final Color searchButtonSplashColor;
final Color? searchButtonSplashColor;

/// Set the icon color inside the search button.
/// If value is null and theme brightness is light, use primaryColor, if dark, use accentColor.
final Color searchButtonIconColor;
final Color? searchButtonIconColor;

/// Whether to use autoCorrect option.
/// Default value is false
Expand All @@ -103,13 +103,13 @@ class OutlineSearchBar extends StatefulWidget {
final bool ignoreSpecialChar;

/// Called whenever a keyword is entered.
final ValueChanged<String> onKeywordChanged;
final ValueChanged<String>? onKeywordChanged;

/// When you press the search button, it is called with the entered keyword.
final ValueChanged<String> onSearchButtonPressed;
final ValueChanged<String>? onSearchButtonPressed;

OutlineSearchBar({
Key key,
Key? key,
this.textEditingController,
this.backgroundColor = const Color(0xFFFEFEFE),
this.borderColor,
Expand Down Expand Up @@ -137,12 +137,9 @@ class OutlineSearchBar extends StatefulWidget {
this.ignoreSpecialChar = false,
this.onKeywordChanged,
this.onSearchButtonPressed
}) : assert(borderWidth != null && elevation >= 0.0),
assert(elevation != null && elevation >= 0.0),
assert(cursorWidth != null && cursorWidth >= 0.0),
assert(hideSearchButton != null),
assert(ignoreWhiteSpace != null),
assert(ignoreSpecialChar != null),
}) : assert(borderWidth >= 0.0),
assert(elevation >= 0.0),
assert(cursorWidth >= 0.0),
super(key: key);

@override
Expand All @@ -151,13 +148,12 @@ class OutlineSearchBar extends StatefulWidget {

/// Class to control the state of [OutlineSearchBar].
class _OutlineSearchBarState extends State<OutlineSearchBar> with TickerProviderStateMixin {
TextEditingController _textEditingController;

AnimationController _animationController;
Animation<double> _curvedAnimation;
late TextEditingController _textEditingController;
late AnimationController _animationController;
late Animation<double> _curvedAnimation;
bool _isShowingClearButton = false;

Color _themeColor;
late Color _themeColor;

void _textEditingControllerListener() {
if (_textEditingController.text.isEmpty && _isShowingClearButton) {
Expand Down Expand Up @@ -185,14 +181,13 @@ class _OutlineSearchBarState extends State<OutlineSearchBar> with TickerProvider

_animationController.reverse();

_textEditingController = widget.textEditingController;
if (_textEditingController == null)
_textEditingController = TextEditingController();
_textEditingController = widget.textEditingController
?? TextEditingController();
_textEditingController.addListener(_textEditingControllerListener);

if (_textEditingController.text.isEmpty
&& (widget.initText != null && widget.initText.isNotEmpty))
_textEditingController.text = widget.initText;
&& (widget.initText != null && widget.initText!.isNotEmpty))
_textEditingController.text = widget.initText!;
}

@override
Expand Down Expand Up @@ -273,11 +268,11 @@ class _OutlineSearchBarState extends State<OutlineSearchBar> with TickerProvider
),
onChanged: (String value) {
if (widget.onKeywordChanged != null)
widget.onKeywordChanged(value);
widget.onKeywordChanged!(value);
},
onSubmitted: (String value) {
if (widget.onSearchButtonPressed != null)
widget.onSearchButtonPressed(value);
widget.onSearchButtonPressed!(value);
},
);
}
Expand All @@ -298,14 +293,14 @@ class _OutlineSearchBarState extends State<OutlineSearchBar> with TickerProvider
margin: const EdgeInsets.all(6.0),
decoration: BoxDecoration(
color: widget.clearButtonColor,
borderRadius: BorderRadius.circular(clearIcon.size)
borderRadius: BorderRadius.circular(clearIcon.size!)
),
child: clearIcon
),
onTap: () {
Future.microtask(_textEditingController.clear);
if (widget.onKeywordChanged != null)
widget.onKeywordChanged("");
widget.onKeywordChanged!("");
}
),
);
Expand All @@ -322,12 +317,12 @@ class _OutlineSearchBarState extends State<OutlineSearchBar> with TickerProvider
color: Colors.transparent,
child: InkWell(
splashColor: widget.searchButtonSplashColor,
borderRadius: BorderRadius.circular(searchIcon.size),
borderRadius: BorderRadius.circular(searchIcon.size!),
child: searchIcon,
onTap: () {
if (widget.onSearchButtonPressed != null) {
FocusScope.of(context).requestFocus(FocusNode());
widget.onSearchButtonPressed(_textEditingController.text);
widget.onSearchButtonPressed!(_textEditingController.text);
}
}
),
Expand Down
42 changes: 21 additions & 21 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -66,28 +66,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0"
simple_text_field:
dependency: "direct main"
description:
name: simple_text_field
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "2.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -99,56 +99,56 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.17.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ author: WOO JIN HWANG <[email protected]>
homepage: https://github.com/Dev-hwang/outline_search_bar

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"

dependencies:
flutter:
sdk: flutter

simple_text_field: ^1.0.2
simple_text_field: ^2.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit cd462e3

Please sign in to comment.