From 53fd0802149a0ac16e51eb07d486d4734401d56c Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 17 May 2021 23:03:52 +0200 Subject: [PATCH] Migrate some widgets to null safety --- lib/widgets/pro_overlay.dart | 4 +--- lib/widgets/rename_dialog.dart | 14 ++++++-------- lib/widgets/sorting_mode_selector.dart | 14 ++++++-------- lib/widgets/sync_button.dart | 18 +++++++++--------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/widgets/pro_overlay.dart b/lib/widgets/pro_overlay.dart index 3c19d812..82d905f7 100644 --- a/lib/widgets/pro_overlay.dart +++ b/lib/widgets/pro_overlay.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -13,7 +11,7 @@ class ProOverlay extends StatelessWidget { final Widget child; final Feature feature; - ProOverlay({@required this.child, @required this.feature}) { + ProOverlay({required this.child, required this.feature}) { assert(feature.pro == true); } diff --git a/lib/widgets/rename_dialog.dart b/lib/widgets/rename_dialog.dart index c960e0ee..5ab01c90 100644 --- a/lib/widgets/rename_dialog.dart +++ b/lib/widgets/rename_dialog.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:io'; import 'package:flutter/material.dart'; @@ -14,9 +12,9 @@ class RenameDialog extends StatefulWidget { final String dialogTitle; RenameDialog({ - @required this.oldPath, - @required this.inputDecoration, - @required this.dialogTitle, + required this.oldPath, + required this.inputDecoration, + required this.dialogTitle, }); @override @@ -24,7 +22,7 @@ class RenameDialog extends StatefulWidget { } class _RenameDialogState extends State { - TextEditingController _textController; + late TextEditingController _textController; final _formKey = GlobalKey(); @override @@ -43,7 +41,7 @@ class _RenameDialogState extends State { TextFormField( decoration: InputDecoration(labelText: widget.inputDecoration), validator: (value) { - if (value.isEmpty) { + if (value!.isEmpty) { return tr('widgets.rename.validator.empty'); } @@ -76,7 +74,7 @@ class _RenameDialogState extends State { ), TextButton( onPressed: () { - if (_formKey.currentState.validate()) { + if (_formKey.currentState!.validate()) { var newName = _textController.text; Navigator.of(context).pop(newName); } diff --git a/lib/widgets/sorting_mode_selector.dart b/lib/widgets/sorting_mode_selector.dart index df35586b..55d6237a 100644 --- a/lib/widgets/sorting_mode_selector.dart +++ b/lib/widgets/sorting_mode_selector.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -17,8 +15,8 @@ class SortingModeSelector extends StatefulWidget { } class _SortingModeSelectorState extends State { - SortingField field; - SortingOrder order; + late SortingField field; + late SortingOrder order; @override void initState() { @@ -68,9 +66,9 @@ class _SortingModeSelectorState extends State { title: Text(sf.toPublicString()), value: sf, groupValue: field, - onChanged: (SortingField sf) { + onChanged: (SortingField? sf) { setState(() { - field = sf; + field = sf!; }); }, ); @@ -81,9 +79,9 @@ class _SortingModeSelectorState extends State { title: Text(so.toPublicString()), value: so, groupValue: order, - onChanged: (SortingOrder so) { + onChanged: (SortingOrder? so) { setState(() { - order = so; + order = so!; }); }, ); diff --git a/lib/widgets/sync_button.dart b/lib/widgets/sync_button.dart index dde1faab..7ecef703 100644 --- a/lib/widgets/sync_button.dart +++ b/lib/widgets/sync_button.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; @@ -19,8 +19,8 @@ class SyncButton extends StatefulWidget { } class _SyncButtonState extends State { - StreamSubscription subscription; - ConnectivityResult _connectivity; + late StreamSubscription subscription; + ConnectivityResult? _connectivity; @override void initState() { @@ -126,7 +126,7 @@ class BlinkingIcon extends StatefulWidget { final Widget child; final int interval; - BlinkingIcon({@required this.child, this.interval = 500, Key key}) + BlinkingIcon({required this.child, this.interval = 500, Key? key}) : super(key: key); @override @@ -135,8 +135,8 @@ class BlinkingIcon extends StatefulWidget { class _BlinkingIconState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _animation; + late AnimationController _controller; + late Animation _animation; @override void initState() { @@ -172,13 +172,13 @@ class _BlinkingIconState extends State class GitPendingChangesBadge extends StatelessWidget { final Widget child; - GitPendingChangesBadge({@required this.child}); + GitPendingChangesBadge({required this.child}); @override Widget build(BuildContext context) { var theme = Theme.of(context); var darkMode = theme.brightness == Brightness.dark; - var style = theme.textTheme.caption.copyWith( + var style = theme.textTheme.caption!.copyWith( fontSize: 6.0, color: darkMode ? Colors.black : Colors.white, ); @@ -188,7 +188,7 @@ class GitPendingChangesBadge extends StatelessWidget { return Badge( badgeContent: Text(repo.numChanges.toString(), style: style), showBadge: repo.numChanges != 0, - badgeColor: theme.iconTheme.color, + badgeColor: theme.iconTheme.color!, position: BadgePosition.topEnd(top: 10.0, end: 4.0), child: child, );