diff --git a/lib/app.dart b/lib/app.dart index 3d244363c..24aa3ebbf 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:io'; @@ -23,7 +23,7 @@ class EnteApp extends StatefulWidget { const EnteApp( this.runBackgroundTask, this.killBackgroundTask, { - Key key, + Key? key, }) : super(key: key); @override diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index 6eb1a0633..899bfd57d 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -614,7 +614,7 @@ class Configuration { return _preferences.setBool(keyShouldHideFromRecents, value); } - void setVolatilePassword(String volatilePassword) { + void setVolatilePassword(String? volatilePassword) { _volatilePassword = volatilePassword; } diff --git a/lib/main.dart b/lib/main.dart index 5e5f857fa..decd2cd68 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; import 'dart:io'; @@ -230,7 +230,7 @@ Future _isRunningInForeground() async { (currentTime - kFGTaskDeathTimeoutInMicroseconds); } -Future _killBGTask([String taskId]) async { +Future _killBGTask([String? taskId]) async { await UploadLocksDB.instance.releaseLocksAcquiredByOwnerBefore( ProcessType.background.toString(), DateTime.now().microsecondsSinceEpoch, @@ -281,7 +281,7 @@ Future _logFGHeartBeatInfo() async { _logger.info('isAlreaduunningFG: $isRunningInFG, last Beat: $lastRun'); } -void _scheduleSuicide(Duration duration, [String taskID]) { +void _scheduleSuicide(Duration duration, [String? taskID]) { final taskIDVal = taskID ?? 'no taskID'; _logger.warning("Schedule seppuku taskID: $taskIDVal"); Future.delayed(duration, () { diff --git a/lib/services/local_authentication_service.dart b/lib/services/local_authentication_service.dart index f55c529fd..4e218f18a 100644 --- a/lib/services/local_authentication_service.dart +++ b/lib/services/local_authentication_service.dart @@ -16,9 +16,9 @@ class LocalAuthenticationService { String infoMessage, ) async { if (await _isLocalAuthSupportedOnDevice()) { - AppLock.of(context).setEnabled(false); + AppLock.of(context)!.setEnabled(false); final result = await requestAuthentication(infoMessage); - AppLock.of(context).setEnabled( + AppLock.of(context)!.setEnabled( Configuration.instance.shouldShowLockScreen(), ); if (!result) { @@ -39,17 +39,17 @@ class LocalAuthenticationService { String errorDialogTitle = "", ]) async { if (await _isLocalAuthSupportedOnDevice()) { - AppLock.of(context).disable(); + AppLock.of(context)!.disable(); final result = await requestAuthentication( infoMessage, ); if (result) { - AppLock.of(context).setEnabled(shouldEnableLockScreen); + AppLock.of(context)!.setEnabled(shouldEnableLockScreen); await Configuration.instance .setShouldShowLockScreen(shouldEnableLockScreen); return true; } else { - AppLock.of(context) + AppLock.of(context)! .setEnabled(Configuration.instance.shouldShowLockScreen()); } } else { diff --git a/lib/ui/account/email_entry_page.dart b/lib/ui/account/email_entry_page.dart index bcd6db6b8..a59dbd0ba 100644 --- a/lib/ui/account/email_entry_page.dart +++ b/lib/ui/account/email_entry_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:email_validator/email_validator.dart'; import 'package:flutter/gestures.dart'; @@ -13,7 +13,7 @@ import 'package:photos/ui/common/web_page.dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; class EmailEntryPage extends StatefulWidget { - const EmailEntryPage({Key key}) : super(key: key); + const EmailEntryPage({Key? key}) : super(key: key); @override State createState() => _EmailEntryPageState(); @@ -28,13 +28,13 @@ class _EmailEntryPageState extends State { final _passwordController2 = TextEditingController(); final Color _validFieldValueColor = const Color.fromRGBO(45, 194, 98, 0.2); - String _email; - String _password; + String? _email; + String? _password; String _cnfPassword = ''; double _passwordStrength = 0.0; bool _emailIsValid = false; - bool _hasAgreedToTOS = true; - bool _hasAgreedToE2E = false; + bool? _hasAgreedToTOS = true; + bool? _hasAgreedToE2E = false; bool _password1Visible = false; bool _password2Visible = false; bool _passwordsMatch = false; @@ -65,7 +65,7 @@ class _EmailEntryPageState extends State { Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -104,9 +104,9 @@ class _EmailEntryPageState extends State { buttonText: 'Create account', onPressedFunction: () { _config.setVolatilePassword(_passwordController1.text); - UserService.instance.setEmail(_email); + UserService.instance.setEmail(_email!); UserService.instance - .sendOtt(context, _email, isCreateAccountScreen: true); + .sendOtt(context, _email!, isCreateAccountScreen: true); FocusScope.of(context).unfocus(); }, ), @@ -162,7 +162,7 @@ class _EmailEntryPageState extends State { size: 20, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -170,9 +170,9 @@ class _EmailEntryPageState extends State { ), onChanged: (value) { _email = value.trim(); - if (_emailIsValid != EmailValidator.validate(_email)) { + if (_emailIsValid != EmailValidator.validate(_email!)) { setState(() { - _emailIsValid = EmailValidator.validate(_email); + _emailIsValid = EmailValidator.validate(_email!); }); } }, @@ -220,7 +220,7 @@ class _EmailEntryPageState extends State { Icons.check, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -287,7 +287,7 @@ class _EmailEntryPageState extends State { Icons.check, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -352,7 +352,7 @@ class _EmailEntryPageState extends State { return GestureDetector( onTap: () { setState(() { - _hasAgreedToTOS = !_hasAgreedToTOS; + _hasAgreedToTOS = !_hasAgreedToTOS!; }); }, behavior: HitTestBehavior.translucent, @@ -416,7 +416,7 @@ class _EmailEntryPageState extends State { ], style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 12), ), textAlign: TextAlign.left, @@ -431,7 +431,7 @@ class _EmailEntryPageState extends State { return GestureDetector( onTap: () { setState(() { - _hasAgreedToE2E = !_hasAgreedToE2E; + _hasAgreedToE2E = !_hasAgreedToE2E!; }); }, behavior: HitTestBehavior.translucent, @@ -477,7 +477,7 @@ class _EmailEntryPageState extends State { ], style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 12), ), textAlign: TextAlign.left, @@ -491,8 +491,8 @@ class _EmailEntryPageState extends State { bool _isFormValid() { return _emailIsValid && _passwordsMatch && - _hasAgreedToTOS && - _hasAgreedToE2E && + _hasAgreedToTOS! && + _hasAgreedToE2E! && _passwordIsValid; } } diff --git a/lib/ui/account/login_page.dart b/lib/ui/account/login_page.dart index 9b6cb88b0..1c824f208 100644 --- a/lib/ui/account/login_page.dart +++ b/lib/ui/account/login_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:email_validator/email_validator.dart'; import 'package:flutter/gestures.dart'; @@ -9,7 +9,7 @@ import 'package:photos/ui/common/dynamic_fab.dart'; import 'package:photos/ui/common/web_page.dart'; class LoginPage extends StatefulWidget { - const LoginPage({Key key}) : super(key: key); + const LoginPage({Key? key}) : super(key: key); @override State createState() => _LoginPageState(); @@ -18,8 +18,8 @@ class LoginPage extends StatefulWidget { class _LoginPageState extends State { final _config = Configuration.instance; bool _emailIsValid = false; - String _email; - Color _emailInputFieldColor; + String? _email; + Color? _emailInputFieldColor; @override void initState() { @@ -31,7 +31,7 @@ class _LoginPageState extends State { Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -57,9 +57,9 @@ class _LoginPageState extends State { isFormValid: _emailIsValid, buttonText: 'Log in', onPressedFunction: () { - UserService.instance.setEmail(_email); + UserService.instance.setEmail(_email!); UserService.instance - .sendOtt(context, _email, isCreateAccountScreen: false); + .sendOtt(context, _email!, isCreateAccountScreen: false); FocusScope.of(context).unfocus(); }, ), @@ -105,7 +105,7 @@ class _LoginPageState extends State { size: 20, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -114,7 +114,7 @@ class _LoginPageState extends State { onChanged: (value) { setState(() { _email = value.trim(); - _emailIsValid = EmailValidator.validate(_email); + _emailIsValid = EmailValidator.validate(_email!); if (_emailIsValid) { _emailInputFieldColor = const Color.fromRGBO(45, 194, 98, 0.2); @@ -145,7 +145,7 @@ class _LoginPageState extends State { text: TextSpan( style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 12), children: [ const TextSpan( diff --git a/lib/ui/account/ott_verification_page.dart b/lib/ui/account/ott_verification_page.dart index 19932e94a..f9bcc4804 100644 --- a/lib/ui/account/ott_verification_page.dart +++ b/lib/ui/account/ott_verification_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; @@ -15,7 +15,7 @@ class OTTVerificationPage extends StatefulWidget { this.email, { this.isChangeEmail = false, this.isCreateAccountScreen = false, - Key key, + Key? key, }) : super(key: key); @override @@ -29,7 +29,7 @@ class _OTTVerificationPageState extends State { Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -114,7 +114,7 @@ class _OTTVerificationPageState extends State { text: TextSpan( style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 14), children: [ const TextSpan(text: "We've sent a mail to "), @@ -134,7 +134,7 @@ class _OTTVerificationPageState extends State { 'Please check your inbox (and spam) to complete verification', style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 14), ), ], @@ -187,7 +187,7 @@ class _OTTVerificationPageState extends State { }, child: Text( "Resend email", - style: Theme.of(context).textTheme.subtitle1.copyWith( + style: Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), diff --git a/lib/ui/account/password_entry_page.dart b/lib/ui/account/password_entry_page.dart index 4545c38ed..2895913e9 100644 --- a/lib/ui/account/password_entry_page.dart +++ b/lib/ui/account/password_entry_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -26,7 +26,7 @@ enum PasswordEntryMode { class PasswordEntryPage extends StatefulWidget { final PasswordEntryMode mode; - const PasswordEntryPage({this.mode = PasswordEntryMode.set, Key key}) + const PasswordEntryPage({this.mode = PasswordEntryMode.set, Key? key}) : super(key: key); @override @@ -41,7 +41,7 @@ class _PasswordEntryPageState extends State { final _passwordController1 = TextEditingController(), _passwordController2 = TextEditingController(); final Color _validFieldValueColor = const Color.fromRGBO(45, 194, 98, 0.2); - String _volatilePassword; + String? _volatilePassword; String _passwordInInputBox = ''; String _passwordInInputConfirmationBox = ''; double _passwordStrength = 0.0; @@ -62,7 +62,7 @@ class _PasswordEntryPageState extends State { if (_volatilePassword != null) { Future.delayed( Duration.zero, - () => _showRecoveryCodeDialog(_volatilePassword), + () => _showRecoveryCodeDialog(_volatilePassword!), ); } _password1FocusNode.addListener(() { @@ -81,7 +81,7 @@ class _PasswordEntryPageState extends State { Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -167,7 +167,7 @@ class _PasswordEntryPageState extends State { textAlign: TextAlign.start, style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 14), ), ), @@ -178,7 +178,7 @@ class _PasswordEntryPageState extends State { text: TextSpan( style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 14), children: [ const TextSpan( @@ -187,7 +187,7 @@ class _PasswordEntryPageState extends State { ), TextSpan( text: "we cannot decrypt your data", - style: Theme.of(context).textTheme.subtitle1.copyWith( + style: Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), @@ -245,7 +245,7 @@ class _PasswordEntryPageState extends State { Icons.check, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -307,7 +307,7 @@ class _PasswordEntryPageState extends State { Icons.check, color: Theme.of(context) .inputDecorationTheme - .focusedBorder + .focusedBorder! .borderSide .color, ) @@ -364,7 +364,7 @@ class _PasswordEntryPageState extends State { child: RichText( text: TextSpan( text: "How it works", - style: Theme.of(context).textTheme.subtitle1.copyWith( + style: Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), diff --git a/lib/ui/account/password_reentry_page.dart b/lib/ui/account/password_reentry_page.dart index aa76835b4..71fe4f0e6 100644 --- a/lib/ui/account/password_reentry_page.dart +++ b/lib/ui/account/password_reentry_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; @@ -17,7 +17,7 @@ import 'package:photos/utils/dialog_util.dart'; import 'package:photos/utils/email_util.dart'; class PasswordReentryPage extends StatefulWidget { - const PasswordReentryPage({Key key}) : super(key: key); + const PasswordReentryPage({Key? key}) : super(key: key); @override State createState() => _PasswordReentryPageState(); @@ -27,7 +27,7 @@ class _PasswordReentryPageState extends State { final _logger = Logger((_PasswordReentryPageState).toString()); final _passwordController = TextEditingController(); final FocusNode _passwordFocusNode = FocusNode(); - String email; + String? email; bool _passwordInFocus = false; bool _passwordVisible = false; @@ -46,7 +46,7 @@ class _PasswordReentryPageState extends State { Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -78,7 +78,7 @@ class _PasswordReentryPageState extends State { try { await Configuration.instance.decryptAndSaveSecrets( _passwordController.text, - Configuration.instance.getKeyAttributes(), + Configuration.instance.getKeyAttributes()!, ); } on KeyDerivationError catch (e, s) { _logger.severe("Password verification failed", e, s); @@ -245,7 +245,7 @@ class _PasswordReentryPageState extends State { child: Text( "Forgot password", style: - Theme.of(context).textTheme.subtitle1.copyWith( + Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), @@ -267,7 +267,7 @@ class _PasswordReentryPageState extends State { child: Text( "Change email", style: - Theme.of(context).textTheme.subtitle1.copyWith( + Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), diff --git a/lib/ui/account/recovery_key_page.dart b/lib/ui/account/recovery_key_page.dart index 0867bd2e2..0fe7e6107 100644 --- a/lib/ui/account/recovery_key_page.dart +++ b/lib/ui/account/recovery_key_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:io' as io; @@ -15,20 +15,20 @@ import 'package:share_plus/share_plus.dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; class RecoveryKeyPage extends StatefulWidget { - final bool showAppBar; + final bool? showAppBar; final String recoveryKey; final String doneText; - final Function() onDone; - final bool isDismissible; - final String title; - final String text; - final String subText; + final Function()? onDone; + final bool? isDismissible; + final String? title; + final String? text; + final String? subText; final bool showProgressBar; const RecoveryKeyPage( this.recoveryKey, this.doneText, { - Key key, + Key? key, this.showAppBar, this.onDone, this.isDismissible, @@ -56,7 +56,7 @@ class _RecoveryKeyPageState extends State { 'recovery code should have $mnemonicKeyWordCount words', ); } - final double topPadding = widget.showAppBar + final double topPadding = widget.showAppBar! ? 40 : widget.showProgressBar ? 32 @@ -79,7 +79,7 @@ class _RecoveryKeyPageState extends State { ), ), ) - : widget.showAppBar + : widget.showAppBar! ? AppBar( elevation: 0, title: Text(widget.title ?? "Recovery key"), @@ -100,14 +100,14 @@ class _RecoveryKeyPageState extends State { mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [ - widget.showAppBar + widget.showAppBar! ? const SizedBox.shrink() : Text( widget.title ?? "Recovery key", style: Theme.of(context).textTheme.headline4, ), Padding( - padding: EdgeInsets.all(widget.showAppBar ? 0 : 12), + padding: EdgeInsets.all(widget.showAppBar! ? 0 : 12), ), Text( widget.text ?? @@ -263,6 +263,6 @@ class _RecoveryKeyPageState extends State { if (_recoveryKeyFile.existsSync()) { await _recoveryKeyFile.delete(); } - widget.onDone(); + widget.onDone!(); } } diff --git a/lib/ui/account/recovery_page.dart b/lib/ui/account/recovery_page.dart index 3d74d72de..72532d8f2 100644 --- a/lib/ui/account/recovery_page.dart +++ b/lib/ui/account/recovery_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:ui'; @@ -10,7 +10,7 @@ import 'package:photos/utils/dialog_util.dart'; import 'package:photos/utils/toast_util.dart'; class RecoveryPage extends StatefulWidget { - const RecoveryPage({Key key}) : super(key: key); + const RecoveryPage({Key? key}) : super(key: key); @override State createState() => _RecoveryPageState(); @@ -22,7 +22,7 @@ class _RecoveryPageState extends State { @override Widget build(BuildContext context) { final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100; - FloatingActionButtonLocation fabLocation() { + FloatingActionButtonLocation? fabLocation() { if (isKeypadOpen) { return null; } else { @@ -140,7 +140,7 @@ class _RecoveryPageState extends State { child: Text( "No recovery key?", style: - Theme.of(context).textTheme.subtitle1.copyWith( + Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, decoration: TextDecoration.underline, ), diff --git a/lib/ui/backup_folder_selection_page.dart b/lib/ui/backup_folder_selection_page.dart index 61a3afab1..dbb0db016 100644 --- a/lib/ui/backup_folder_selection_page.dart +++ b/lib/ui/backup_folder_selection_page.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:io'; import 'dart:ui'; @@ -24,9 +22,9 @@ class BackupFolderSelectionPage extends StatefulWidget { final String buttonText; const BackupFolderSelectionPage({ - @required this.buttonText, + required this.buttonText, this.isOnboarding = false, - Key key, + Key? key, }) : super(key: key); @override @@ -38,8 +36,8 @@ class _BackupFolderSelectionPageState extends State { final Logger _logger = Logger((_BackupFolderSelectionPageState).toString()); final Set _allDevicePathIDs = {}; final Set _selectedDevicePathIDs = {}; - List _deviceCollections; - Map _pathIDToItemCount; + List? _deviceCollections; + Map? _pathIDToItemCount; @override void initState() { @@ -50,10 +48,10 @@ class _BackupFolderSelectionPageState extends State { await FilesDB.instance.getDevicePathIDToImportedFileCount(); setState(() { _deviceCollections = files; - _deviceCollections.sort((first, second) { + _deviceCollections!.sort((first, second) { return first.name.toLowerCase().compareTo(second.name.toLowerCase()); }); - for (final file in _deviceCollections) { + for (final file in _deviceCollections!) { _allDevicePathIDs.add(file.id); if (file.shouldBackup) { _selectedDevicePathIDs.add(file.id); @@ -103,7 +101,7 @@ class _BackupFolderSelectionPageState extends State { padding: const EdgeInsets.only(left: 24, right: 48), child: Text( "Selected folders will be encrypted and backed up", - style: Theme.of(context).textTheme.caption.copyWith(height: 1.3), + style: Theme.of(context).textTheme.caption!.copyWith(height: 1.3), ), ), const Padding( @@ -139,7 +137,7 @@ class _BackupFolderSelectionPageState extends State { } else { _selectedDevicePathIDs.addAll(_allDevicePathIDs); } - _deviceCollections.sort((first, second) { + _deviceCollections!.sort((first, second) { return first.name .toLowerCase() .compareTo(second.name.toLowerCase()); @@ -191,7 +189,7 @@ class _BackupFolderSelectionPageState extends State { }, child: Text( "Skip", - style: Theme.of(context).textTheme.caption.copyWith( + style: Theme.of(context).textTheme.caption!.copyWith( decoration: TextDecoration.underline, ), ), @@ -247,11 +245,11 @@ class _BackupFolderSelectionPageState extends State { padding: const EdgeInsets.only(right: 4), child: ImplicitlyAnimatedReorderableList( controller: scrollController, - items: _deviceCollections, + items: _deviceCollections!, areItemsTheSame: (oldItem, newItem) => oldItem.id == newItem.id, onReorderFinished: (item, from, to, newItems) { setState(() { - _deviceCollections + _deviceCollections! ..clear() ..addAll(newItems); }); @@ -261,7 +259,7 @@ class _BackupFolderSelectionPageState extends State { key: ValueKey(file), builder: (context, dragAnimation, inDrag) { final t = dragAnimation.value; - final elevation = lerpDouble(0, 8, t); + final elevation = lerpDouble(0, 8, t)!; final themeColor = Theme.of(context).colorScheme.onSurface; final color = Color.lerp(themeColor, themeColor.withOpacity(0.8), t); @@ -288,7 +286,7 @@ class _BackupFolderSelectionPageState extends State { Widget _getFileItem(DeviceCollection deviceCollection) { final isSelected = _selectedDevicePathIDs.contains(deviceCollection.id); final importedCount = _pathIDToItemCount != null - ? _pathIDToItemCount[deviceCollection.id] ?? 0 + ? _pathIDToItemCount![deviceCollection.id] ?? 0 : -1; return Padding( padding: const EdgeInsets.only(bottom: 1, right: 1), @@ -326,7 +324,7 @@ class _BackupFolderSelectionPageState extends State { activeColor: Colors.white, value: isSelected, onChanged: (value) { - if (value) { + if (value!) { _selectedDevicePathIDs.add(deviceCollection.id); } else { _selectedDevicePathIDs.remove(deviceCollection.id); @@ -375,7 +373,7 @@ class _BackupFolderSelectionPageState extends State { ), ], ), - _getThumbnail(deviceCollection.thumbnail, isSelected), + _getThumbnail(deviceCollection.thumbnail!, isSelected), ], ), onTap: () { @@ -393,7 +391,7 @@ class _BackupFolderSelectionPageState extends State { } void _sortFiles() { - _deviceCollections.sort((first, second) { + _deviceCollections!.sort((first, second) { if (_selectedDevicePathIDs.contains(first.id) && _selectedDevicePathIDs.contains(second.id)) { return first.name.toLowerCase().compareTo(second.name.toLowerCase()); diff --git a/lib/ui/collections/device_folders_grid_view_widget.dart b/lib/ui/collections/device_folders_grid_view_widget.dart index 6e514abbe..2ff56d655 100644 --- a/lib/ui/collections/device_folders_grid_view_widget.dart +++ b/lib/ui/collections/device_folders_grid_view_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; @@ -17,7 +17,7 @@ import 'package:photos/ui/viewer/gallery/empty_state.dart'; class DeviceFoldersGridViewWidget extends StatefulWidget { const DeviceFoldersGridViewWidget({ - Key key, + Key? key, }) : super(key: key); @override @@ -27,8 +27,8 @@ class DeviceFoldersGridViewWidget extends StatefulWidget { class _DeviceFoldersGridViewWidgetState extends State { - StreamSubscription _backupFoldersUpdatedEvent; - StreamSubscription _localFilesSubscription; + StreamSubscription? _backupFoldersUpdatedEvent; + StreamSubscription? _localFilesSubscription; String _loadReason = "init"; @override @@ -65,7 +65,7 @@ class _DeviceFoldersGridViewWidgetState .getDeviceCollections(includeCoverThumbnail: true), builder: (context, snapshot) { if (snapshot.hasData) { - return snapshot.data.isEmpty + return snapshot.data!.isEmpty ? Padding( padding: const EdgeInsets.all(22), child: (isMigrationDone @@ -81,10 +81,10 @@ class _DeviceFoldersGridViewWidgetState physics: const ScrollPhysics(), // to disable GridView's scrolling itemBuilder: (context, index) { - final deviceCollection = snapshot.data[index]; + final deviceCollection = snapshot.data![index]; return DeviceFolderIcon(deviceCollection); }, - itemCount: snapshot.data.length, + itemCount: snapshot.data!.length, ); } else if (snapshot.hasError) { logger.severe("failed to load device gallery", snapshot.error); diff --git a/lib/ui/collections/hidden_collections_button_widget.dart b/lib/ui/collections/hidden_collections_button_widget.dart index 284a77a65..036762a24 100644 --- a/lib/ui/collections/hidden_collections_button_widget.dart +++ b/lib/ui/collections/hidden_collections_button_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/services/local_authentication_service.dart'; @@ -10,7 +10,7 @@ class HiddenCollectionsButtonWidget extends StatelessWidget { const HiddenCollectionsButtonWidget( this.textStyle, { - Key key, + Key? key, }) : super(key: key); @override @@ -24,7 +24,7 @@ class HiddenCollectionsButtonWidget extends StatelessWidget { padding: const EdgeInsets.all(0), side: BorderSide( width: 0.5, - color: Theme.of(context).iconTheme.color.withOpacity(0.24), + color: Theme.of(context).iconTheme.color!.withOpacity(0.24), ), ), child: SizedBox( diff --git a/lib/ui/collections/remote_collections_grid_view_widget.dart b/lib/ui/collections/remote_collections_grid_view_widget.dart index 4d20e1a9c..5aa1b29ab 100644 --- a/lib/ui/collections/remote_collections_grid_view_widget.dart +++ b/lib/ui/collections/remote_collections_grid_view_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:math'; @@ -17,11 +17,11 @@ class RemoteCollectionsGridViewWidget extends StatelessWidget { static const fixedGapBetweenAlbum = 8.0; static const minGapForHorizontalPadding = 8.0; - final List collections; + final List? collections; const RemoteCollectionsGridViewWidget( this.collections, { - Key key, + Key? key, }) : super(key: key); @override @@ -46,13 +46,13 @@ class RemoteCollectionsGridViewWidget extends StatelessWidget { physics: const ScrollPhysics(), // to disable GridView's scrolling itemBuilder: (context, index) { - if (index < collections.length) { - return CollectionItem(collections[index], sideOfThumbnail); + if (index < collections!.length) { + return CollectionItem(collections![index], sideOfThumbnail); } else { return const CreateNewAlbumWidget(); } }, - itemCount: collections.length + 1, + itemCount: collections!.length + 1, // To include the + button gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: albumsCountInOneRow, diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index fc4fbbb13..49cb718b3 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; @@ -26,7 +26,7 @@ import 'package:photos/ui/viewer/gallery/empty_state.dart'; import 'package:photos/utils/local_settings.dart'; class CollectionsGalleryWidget extends StatefulWidget { - const CollectionsGalleryWidget({Key key}) : super(key: key); + const CollectionsGalleryWidget({Key? key}) : super(key: key); @override State createState() => @@ -36,10 +36,10 @@ class CollectionsGalleryWidget extends StatefulWidget { class _CollectionsGalleryWidgetState extends State with AutomaticKeepAliveClientMixin { final _logger = Logger((_CollectionsGalleryWidgetState).toString()); - StreamSubscription _localFilesSubscription; - StreamSubscription _collectionUpdatesSubscription; - StreamSubscription _loggedOutEvent; - AlbumSortKey sortKey; + late StreamSubscription _localFilesSubscription; + late StreamSubscription _collectionUpdatesSubscription; + late StreamSubscription _loggedOutEvent; + AlbumSortKey? sortKey; String _loadReason = "init"; @override @@ -98,8 +98,8 @@ class _CollectionsGalleryWidgetState extends State (first, second) { if (sortKey == AlbumSortKey.albumName) { return compareAsciiLowerCaseNatural( - first.collection.name, - second.collection.name, + first.collection.name!, + second.collection.name!, ); } else if (sortKey == AlbumSortKey.newestPhoto) { return (second.thumbnail?.creationTime ?? -1 * intMaxValue) @@ -121,13 +121,13 @@ class _CollectionsGalleryWidgetState extends State } Widget _getCollectionsGalleryWidget( - List collections, + List? collections, ) { final TextStyle trashAndHiddenTextStyle = Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith( - color: Theme.of(context).textTheme.subtitle1.color.withOpacity(0.5), + color: Theme.of(context).textTheme.subtitle1!.color!.withOpacity(0.5), ); return SingleChildScrollView( @@ -190,9 +190,9 @@ class _CollectionsGalleryWidgetState extends State } return Text( text, - style: Theme.of(context).textTheme.subtitle1.copyWith( + style: Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, - color: Theme.of(context).iconTheme.color.withOpacity(0.7), + color: Theme.of(context).iconTheme.color!.withOpacity(0.7), ), ); } @@ -228,7 +228,7 @@ class _CollectionsGalleryWidgetState extends State ), onSelected: (int index) async { sortKey = AlbumSortKey.values[index]; - await LocalSettings.instance.setAlbumSortKey(sortKey); + await LocalSettings.instance.setAlbumSortKey(sortKey!); setState(() {}); }, itemBuilder: (context) { diff --git a/lib/ui/common/DividerWithPadding.dart b/lib/ui/common/DividerWithPadding.dart index 8be210db2..94b20d9c2 100644 --- a/lib/ui/common/DividerWithPadding.dart +++ b/lib/ui/common/DividerWithPadding.dart @@ -1,11 +1,11 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; class DividerWithPadding extends StatelessWidget { final double left, top, right, bottom, thinckness; const DividerWithPadding({ - Key key, + Key? key, this.left = 0, this.top = 0, this.right = 0, diff --git a/lib/ui/common/bottom_shadow.dart b/lib/ui/common/bottom_shadow.dart index 08dd69f23..6003e199d 100644 --- a/lib/ui/common/bottom_shadow.dart +++ b/lib/ui/common/bottom_shadow.dart @@ -1,11 +1,11 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; class BottomShadowWidget extends StatelessWidget { final double offsetDy; - final Color shadowColor; - const BottomShadowWidget({this.offsetDy = 28, this.shadowColor, Key key}) + final Color? shadowColor; + const BottomShadowWidget({this.offsetDy = 28, this.shadowColor, Key? key}) : super(key: key); @override diff --git a/lib/ui/common/dialogs.dart b/lib/ui/common/dialogs.dart index 8d19a5e98..0e9a23415 100644 --- a/lib/ui/common/dialogs.dart +++ b/lib/ui/common/dialogs.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; @@ -11,14 +11,14 @@ enum ActionType { } // if dialog is dismissed by tapping outside, this will return null -Future showChoiceDialog( +Future showChoiceDialog( BuildContext context, String title, String content, { String firstAction = 'Ok', - Color firstActionColor, + Color? firstActionColor, String secondAction = 'Cancel', - Color secondActionColor, + Color? secondActionColor, ActionType actionType = ActionType.confirm, }) { final AlertDialog alert = AlertDialog( diff --git a/lib/ui/common/dynamic_fab.dart b/lib/ui/common/dynamic_fab.dart index abcdaa141..32abb83d7 100644 --- a/lib/ui/common/dynamic_fab.dart +++ b/lib/ui/common/dynamic_fab.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:math' as math; @@ -6,13 +6,13 @@ import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; class DynamicFAB extends StatelessWidget { - final bool isKeypadOpen; - final bool isFormValid; - final String buttonText; - final Function onPressedFunction; + final bool? isKeypadOpen; + final bool? isFormValid; + final String? buttonText; + final Function? onPressedFunction; const DynamicFAB({ - Key key, + Key? key, this.isKeypadOpen, this.buttonText, this.isFormValid, @@ -21,7 +21,7 @@ class DynamicFAB extends StatelessWidget { @override Widget build(BuildContext context) { - if (isKeypadOpen) { + if (isKeypadOpen!) { return Container( decoration: BoxDecoration( boxShadow: [ @@ -43,13 +43,13 @@ class DynamicFAB extends StatelessWidget { Theme.of(context).colorScheme.dynamicFABBackgroundColor, foregroundColor: Theme.of(context).colorScheme.dynamicFABTextColor, - onPressed: isFormValid - ? onPressedFunction + onPressed: isFormValid! + ? onPressedFunction as void Function()? : () { FocusScope.of(context).unfocus(); }, child: Transform.rotate( - angle: isFormValid ? 0 : math.pi / 2, + angle: isFormValid! ? 0 : math.pi / 2, child: const Icon( Icons.chevron_right, size: 36, @@ -65,8 +65,8 @@ class DynamicFAB extends StatelessWidget { height: 56, padding: const EdgeInsets.symmetric(horizontal: 20), child: OutlinedButton( - onPressed: isFormValid ? onPressedFunction : null, - child: Text(buttonText), + onPressed: isFormValid! ? onPressedFunction as void Function()? : null, + child: Text(buttonText!), ), ); } @@ -75,17 +75,17 @@ class DynamicFAB extends StatelessWidget { class NoScalingAnimation extends FloatingActionButtonAnimator { @override - Offset getOffset({Offset begin, Offset end, double progress}) { + Offset getOffset({Offset? begin, required Offset end, double? progress}) { return end; } @override - Animation getRotationAnimation({Animation parent}) { + Animation getRotationAnimation({required Animation parent}) { return Tween(begin: 1.0, end: 1.0).animate(parent); } @override - Animation getScaleAnimation({Animation parent}) { + Animation getScaleAnimation({required Animation parent}) { return Tween(begin: 1.0, end: 1.0).animate(parent); } } diff --git a/lib/ui/common/gradient_button.dart b/lib/ui/common/gradient_button.dart index 790aca509..d9bd9d603 100644 --- a/lib/ui/common/gradient_button.dart +++ b/lib/ui/common/gradient_button.dart @@ -1,23 +1,23 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/theme/ente_theme.dart'; class GradientButton extends StatelessWidget { final List linearGradientColors; - final Function onTap; + final Function? onTap; // text is ignored if child is specified final String text; // nullable - final IconData iconData; + final IconData? iconData; // padding between the text and icon final double paddingValue; const GradientButton({ - Key key, + Key? key, this.linearGradientColors = const [ Color(0xFF2CD267), Color(0xFF1DB954), @@ -65,7 +65,7 @@ class GradientButton extends StatelessWidget { ); } return InkWell( - onTap: onTap, + onTap: onTap as void Function()?, child: Container( height: 56, decoration: BoxDecoration( diff --git a/lib/ui/common/linear_progress_dialog.dart b/lib/ui/common/linear_progress_dialog.dart index 6cd5c3de2..999f57ef6 100644 --- a/lib/ui/common/linear_progress_dialog.dart +++ b/lib/ui/common/linear_progress_dialog.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; @@ -6,14 +6,14 @@ import 'package:photos/ente_theme_data.dart'; class LinearProgressDialog extends StatefulWidget { final String message; - const LinearProgressDialog(this.message, {Key key}) : super(key: key); + const LinearProgressDialog(this.message, {Key? key}) : super(key: key); @override LinearProgressDialogState createState() => LinearProgressDialogState(); } class LinearProgressDialogState extends State { - double _progress; + double? _progress; @override void initState() { diff --git a/lib/ui/common/progress_dialog.dart b/lib/ui/common/progress_dialog.dart index 616d53f76..a05f031e6 100644 --- a/lib/ui/common/progress_dialog.dart +++ b/lib/ui/common/progress_dialog.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:flutter/material.dart'; enum ProgressDialogType { normal, download } @@ -7,7 +5,7 @@ enum ProgressDialogType { normal, download } String _dialogMessage = "Loading..."; double _progress = 0.0, _maxProgress = 100.0; -Widget _customBody; +Widget? _customBody; TextAlign _textAlign = TextAlign.left; Alignment _progressWidgetAlignment = Alignment.centerLeft; @@ -15,10 +13,10 @@ Alignment _progressWidgetAlignment = Alignment.centerLeft; TextDirection _direction = TextDirection.ltr; bool _isShowing = false; -BuildContext _context, _dismissingContext; -ProgressDialogType _progressDialogType; +BuildContext? _context, _dismissingContext; +ProgressDialogType? _progressDialogType; bool _barrierDismissible = true, _showLogs = false; -Color _barrierColor; +Color? _barrierColor; TextStyle _progressTextStyle = const TextStyle( color: Colors.black, @@ -42,16 +40,16 @@ Widget _progressWidget = Image.asset( ); class ProgressDialog { - _Body _dialog; + _Body? _dialog; ProgressDialog( BuildContext context, { - ProgressDialogType type, - bool isDismissible, - bool showLogs, - TextDirection textDirection, - Widget customBody, - Color barrierColor, + ProgressDialogType? type, + bool? isDismissible, + bool? showLogs, + TextDirection? textDirection, + Widget? customBody, + Color? barrierColor, }) { _context = context; _progressDialogType = type ?? ProgressDialogType.normal; @@ -63,20 +61,20 @@ class ProgressDialog { } void style({ - Widget child, - double progress, - double maxProgress, - String message, - Widget progressWidget, - Color backgroundColor, - TextStyle progressTextStyle, - TextStyle messageTextStyle, - double elevation, - TextAlign textAlign, - double borderRadius, - Curve insetAnimCurve, - EdgeInsets padding, - Alignment progressWidgetAlignment, + Widget? child, + double? progress, + double? maxProgress, + String? message, + Widget? progressWidget, + Color? backgroundColor, + TextStyle? progressTextStyle, + TextStyle? messageTextStyle, + double? elevation, + TextAlign? textAlign, + double? borderRadius, + Curve? insetAnimCurve, + EdgeInsets? padding, + Alignment? progressWidgetAlignment, }) { if (_isShowing) return; if (_progressDialogType == ProgressDialogType.download) { @@ -100,12 +98,12 @@ class ProgressDialog { } void update({ - double progress, - double maxProgress, - String message, - Widget progressWidget, - TextStyle progressTextStyle, - TextStyle messageTextStyle, + double? progress, + double? maxProgress, + String? message, + Widget? progressWidget, + TextStyle? progressTextStyle, + TextStyle? messageTextStyle, }) { if (_progressDialogType == ProgressDialogType.download) { _progress = progress ?? _progress; @@ -117,7 +115,7 @@ class ProgressDialog { _messageStyle = messageTextStyle ?? _messageStyle; _progressTextStyle = progressTextStyle ?? _progressTextStyle; - if (_isShowing) _dialog.update(); + if (_isShowing) _dialog!.update(); } bool isShowing() { @@ -128,7 +126,9 @@ class ProgressDialog { try { if (_isShowing) { _isShowing = false; - Navigator.of(_dismissingContext).pop(); + if (_dismissingContext != null) { + Navigator.of(_dismissingContext!).pop(); + } if (_showLogs) debugPrint('ProgressDialog dismissed'); return Future.value(true); } else { @@ -147,7 +147,7 @@ class ProgressDialog { if (!_isShowing) { _dialog = _Body(); showDialog( - context: _context, + context: _context!, barrierDismissible: _barrierDismissible, barrierColor: _barrierColor, builder: (BuildContext context) { diff --git a/lib/ui/common/rename_dialog.dart b/lib/ui/common/rename_dialog.dart index 5629ae230..b1d125719 100644 --- a/lib/ui/common/rename_dialog.dart +++ b/lib/ui/common/rename_dialog.dart @@ -1,14 +1,14 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/utils/dialog_util.dart'; class RenameDialog extends StatefulWidget { - final String name; + final String? name; final String type; final int maxLength; - const RenameDialog(this.name, this.type, {Key key, this.maxLength = 100}) + const RenameDialog(this.name, this.type, {Key? key, this.maxLength = 100}) : super(key: key); @override @@ -16,7 +16,7 @@ class RenameDialog extends StatefulWidget { } class _RenameDialogState extends State { - String _newName; + String? _newName; @override void initState() { @@ -74,7 +74,7 @@ class _RenameDialogState extends State { ), ), onPressed: () { - if (_newName.trim().isEmpty) { + if (_newName!.trim().isEmpty) { showErrorDialog( context, "Empty name", @@ -82,7 +82,7 @@ class _RenameDialogState extends State { ); return; } - if (_newName.trim().length > widget.maxLength) { + if (_newName!.trim().length > widget.maxLength) { showErrorDialog( context, "Name too large", @@ -90,7 +90,7 @@ class _RenameDialogState extends State { ); return; } - Navigator.of(context).pop(_newName.trim()); + Navigator.of(context).pop(_newName!.trim()); }, ), ], diff --git a/lib/ui/common/web_page.dart b/lib/ui/common/web_page.dart index 46fa69ad5..7a0f08767 100644 --- a/lib/ui/common/web_page.dart +++ b/lib/ui/common/web_page.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; @@ -8,7 +8,7 @@ class WebPage extends StatefulWidget { final String title; final String url; - const WebPage(this.title, this.url, {Key key}) : super(key: key); + const WebPage(this.title, this.url, {Key? key}) : super(key: key); @override State createState() => _WebPageState(); diff --git a/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart b/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart index db78f3e26..8cfdff82e 100644 --- a/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart +++ b/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart @@ -103,12 +103,12 @@ class BottomActionBarWidget extends StatelessWidget { } List _iconButtons(BuildContext context) { - final iconButtonsWithExpansionIcon = [ + final iconButtonsWithExpansionIcon = [ ...?iconButtons, ExpansionIconWidget(expandableController: _expandableController) ]; iconButtonsWithExpansionIcon.removeWhere((element) => element == null); - return iconButtonsWithExpansionIcon as List; + return iconButtonsWithExpansionIcon; } ExpandableThemeData _getExpandableTheme() { diff --git a/lib/ui/create_collection_page.dart b/lib/ui/create_collection_page.dart index 23ff5980a..dfa3d80da 100644 --- a/lib/ui/create_collection_page.dart +++ b/lib/ui/create_collection_page.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; @@ -46,14 +44,14 @@ String _actionName(CollectionActionType type, bool plural) { } class CreateCollectionPage extends StatefulWidget { - final SelectedFiles selectedFiles; - final List sharedFiles; + final SelectedFiles? selectedFiles; + final List? sharedFiles; final CollectionActionType actionType; const CreateCollectionPage( this.selectedFiles, this.sharedFiles, { - Key key, + Key? key, this.actionType = CollectionActionType.addFiles, }) : super(key: key); @@ -63,13 +61,13 @@ class CreateCollectionPage extends StatefulWidget { class _CreateCollectionPageState extends State { final _logger = Logger((_CreateCollectionPageState).toString()); - String _albumName; + late String _albumName; @override Widget build(BuildContext context) { final filesCount = widget.sharedFiles != null - ? widget.sharedFiles.length - : widget.selectedFiles.files.length; + ? widget.sharedFiles!.length + : widget.selectedFiles!.files.length; return Scaffold( appBar: AppBar( title: Text(_actionName(widget.actionType, filesCount > 1)), @@ -134,9 +132,9 @@ class _CreateCollectionPageState extends State { } else if (snapshot.hasData) { return ListView.builder( itemBuilder: (context, index) { - return _buildCollectionItem(snapshot.data[index]); + return _buildCollectionItem(snapshot.data![index]); }, - itemCount: snapshot.data.length, + itemCount: snapshot.data!.length, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), ); @@ -171,7 +169,7 @@ class _CreateCollectionPageState extends State { const Padding(padding: EdgeInsets.all(8)), Expanded( child: Text( - item.collection.name, + item.collection.name!, style: const TextStyle( fontSize: 16, ), @@ -184,8 +182,8 @@ class _CreateCollectionPageState extends State { showShortToast( context, widget.actionType == CollectionActionType.addFiles - ? "Added successfully to " + item.collection.name - : "Moved successfully to " + item.collection.name, + ? "Added successfully to " + item.collection.name! + : "Moved successfully to " + item.collection.name!, ); _navigateToCollection(item.collection); } @@ -305,11 +303,11 @@ class _CreateCollectionPageState extends State { await dialog.show(); try { final int fromCollectionID = - widget.selectedFiles.files.first?.collectionID; + widget.selectedFiles!.files.first.collectionID!; await CollectionsService.instance.move( toCollectionID, fromCollectionID, - widget.selectedFiles.files?.toList(), + widget.selectedFiles!.files?.toList() ?? [], ); await dialog.hide(); RemoteSyncService.instance.sync(silently: true); @@ -318,7 +316,7 @@ class _CreateCollectionPageState extends State { return true; } on AssertionError catch (e) { await dialog.hide(); - showErrorDialog(context, "Oops", e.message); + showErrorDialog(context, "Oops", e.message as String?); return false; } catch (e, s) { _logger.severe("Could not move to album", e, s); @@ -332,15 +330,15 @@ class _CreateCollectionPageState extends State { final dialog = createProgressDialog(context, "Restoring files..."); await dialog.show(); try { - await CollectionsService.instance - .restore(toCollectionID, widget.selectedFiles.files?.toList()); + await CollectionsService.instance.restore( + toCollectionID, widget.selectedFiles!.files?.toList() ?? []); RemoteSyncService.instance.sync(silently: true); widget.selectedFiles?.clearAll(); await dialog.hide(); return true; } on AssertionError catch (e) { await dialog.hide(); - showErrorDialog(context, "Oops", e.message); + showErrorDialog(context, "Oops", e.message as String?); return false; } catch (e, s) { _logger.severe("Could not move to album", e, s); @@ -359,13 +357,18 @@ class _CreateCollectionPageState extends State { if (widget.sharedFiles != null) { filesPendingUpload.addAll( await convertIncomingSharedMediaToFile( - widget.sharedFiles, + widget.sharedFiles!, collectionID, ), ); } else { - for (final file in widget.selectedFiles.files) { - final currentFile = await FilesDB.instance.getFile(file.generatedID); + for (final file in widget.selectedFiles!.files) { + final File? currentFile = + await (FilesDB.instance.getFile(file.generatedID!)); + if (currentFile == null) { + _logger.severe("Failed to find fileBy genID"); + continue; + } if (currentFile.uploadedFileID == null) { currentFile.collectionID = collectionID; filesPendingUpload.add(currentFile); @@ -396,8 +399,8 @@ class _CreateCollectionPageState extends State { return false; } - Future _createAlbum(String albumName) async { - Collection collection; + Future _createAlbum(String albumName) async { + Collection? collection; final dialog = createProgressDialog(context, "Creating album..."); await dialog.show(); try { diff --git a/lib/ui/extents_page_view.dart b/lib/ui/extents_page_view.dart index f688d8653..7f5835221 100644 --- a/lib/ui/extents_page_view.dart +++ b/lib/ui/extents_page_view.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; @@ -49,10 +49,10 @@ class ExtentsPageView extends StatefulWidget { /// child that could possibly be displayed in the page view, instead of just /// those children that are actually visible. ExtentsPageView({ - Key key, + Key? key, this.scrollDirection = Axis.horizontal, this.reverse = false, - PageController controller, + PageController? controller, this.physics, this.pageSnapping = true, this.onPageChanged, @@ -81,15 +81,15 @@ class ExtentsPageView extends StatefulWidget { /// you are planning to change child order at a later time, consider using /// [PageView] or [PageView.custom]. ExtentsPageView.builder({ - Key key, + Key? key, this.scrollDirection = Axis.horizontal, this.reverse = false, - PageController controller, + PageController? controller, this.physics, this.pageSnapping = true, this.onPageChanged, - @required IndexedWidgetBuilder itemBuilder, - int itemCount, + required IndexedWidgetBuilder itemBuilder, + int? itemCount, this.dragStartBehavior = DragStartBehavior.start, this.openDrawer, }) : controller = controller ?? _defaultPageController, @@ -99,16 +99,16 @@ class ExtentsPageView extends StatefulWidget { super(key: key); ExtentsPageView.extents({ - Key key, + Key? key, this.extents = 1, this.scrollDirection = Axis.horizontal, this.reverse = false, - PageController controller, + PageController? controller, this.physics, this.pageSnapping = true, this.onPageChanged, - @required IndexedWidgetBuilder itemBuilder, - int itemCount, + required IndexedWidgetBuilder itemBuilder, + int? itemCount, this.dragStartBehavior = DragStartBehavior.start, this.openDrawer, }) : controller = controller ?? _defaultPageController, @@ -201,14 +201,14 @@ class ExtentsPageView extends StatefulWidget { /// ``` /// {@end-tool} ExtentsPageView.custom({ - Key key, + Key? key, this.scrollDirection = Axis.horizontal, this.reverse = false, - PageController controller, + PageController? controller, this.physics, this.pageSnapping = true, this.onPageChanged, - @required this.childrenDelegate, + required this.childrenDelegate, this.dragStartBehavior = DragStartBehavior.start, this.openDrawer, }) : assert(childrenDelegate != null), @@ -257,13 +257,13 @@ class ExtentsPageView extends StatefulWidget { /// [PageScrollPhysics] prior to being used. /// /// Defaults to matching platform conventions. - final ScrollPhysics physics; + final ScrollPhysics? physics; /// Set to false to disable page snapping, useful for custom scroll behavior. final bool pageSnapping; /// Called whenever the page in the center of the viewport changes. - final ValueChanged onPageChanged; + final ValueChanged? onPageChanged; /// A delegate that provides the children for the [PageView]. /// @@ -276,7 +276,7 @@ class ExtentsPageView extends StatefulWidget { /// {@macro flutter.widgets.scrollable.dragStartBehavior} final DragStartBehavior dragStartBehavior; - final Function openDrawer; //nullable + final Function? openDrawer; //nullable @override State createState() => _PageViewState(); @@ -292,7 +292,7 @@ class _PageViewState extends State { widget.openDrawer != null ? widget.controller.addListener(() { if (widget.controller.offset < -45) { - widget.openDrawer(); + widget.openDrawer!(); } }) : null; @@ -304,7 +304,7 @@ class _PageViewState extends State { super.dispose(); } - AxisDirection _getDirection(BuildContext context) { + AxisDirection? _getDirection(BuildContext context) { switch (widget.scrollDirection) { case Axis.horizontal: assert(debugCheckHasDirectionality(context)); @@ -322,8 +322,8 @@ class _PageViewState extends State { @override Widget build(BuildContext context) { - final AxisDirection axisDirection = _getDirection(context); - final ScrollPhysics physics = widget.pageSnapping + final AxisDirection axisDirection = _getDirection(context)!; + final ScrollPhysics? physics = widget.pageSnapping ? _kPagePhysics.applyTo(widget.physics) : widget.physics; @@ -332,11 +332,11 @@ class _PageViewState extends State { if (notification.depth == 0 && widget.onPageChanged != null && notification is ScrollUpdateNotification) { - final PageMetrics metrics = notification.metrics; - final int currentPage = metrics.page.round(); + final PageMetrics metrics = notification.metrics as PageMetrics; + final int currentPage = metrics.page!.round(); if (currentPage != _lastReportedPage) { _lastReportedPage = currentPage; - widget.onPageChanged(currentPage); + widget.onPageChanged!(currentPage); } } return false; diff --git a/lib/ui/home/header_error_widget.dart b/lib/ui/home/header_error_widget.dart index d6b95d5d6..8e226e95f 100644 --- a/lib/ui/home/header_error_widget.dart +++ b/lib/ui/home/header_error_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/core/errors.dart'; @@ -7,9 +7,9 @@ import 'package:photos/ui/payment/subscription.dart'; import 'package:photos/utils/email_util.dart'; class HeaderErrorWidget extends StatelessWidget { - final Error _error; + final Error? _error; - const HeaderErrorWidget({Key key, @required Error error}) + const HeaderErrorWidget({Key? key, required Error? error}) : _error = error, super(key: key); @@ -123,7 +123,7 @@ class HeaderErrorWidget extends StatelessWidget { padding: const EdgeInsets.fromLTRB(50, 16, 50, 16), side: BorderSide( width: 2, - color: Colors.orange[600], + color: Colors.orange[600]!, ), ), child: Text( diff --git a/lib/ui/home/home_gallery_widget.dart b/lib/ui/home/home_gallery_widget.dart index adebbe00c..20b8bfd1f 100644 --- a/lib/ui/home/home_gallery_widget.dart +++ b/lib/ui/home/home_gallery_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/core/event_bus.dart'; @@ -16,12 +16,12 @@ import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart'; import 'package:photos/ui/viewer/gallery/gallery.dart'; class HomeGalleryWidget extends StatelessWidget { - final Widget header; - final Widget footer; - final SelectedFiles selectedFiles; + final Widget? header; + final Widget? footer; + final SelectedFiles? selectedFiles; const HomeGalleryWidget({ - Key key, + Key? key, this.header, this.footer, this.selectedFiles, @@ -42,7 +42,7 @@ class HomeGalleryWidget extends StatelessWidget { result = await FilesDB.instance.getAllLocalAndUploadedFiles( creationStartTime, creationEndTime, - ownerID, + ownerID!, limit: limit, asc: asc, ignoredCollectionIDs: collectionsToHide, @@ -51,7 +51,7 @@ class HomeGalleryWidget extends StatelessWidget { result = await FilesDB.instance.getAllPendingOrUploadedFiles( creationStartTime, creationEndTime, - ownerID, + ownerID!, limit: limit, asc: asc, ignoredCollectionIDs: collectionsToHide, @@ -88,7 +88,7 @@ class HomeGalleryWidget extends StatelessWidget { return Stack( children: [ gallery, - FileSelectionOverlayBar(GalleryType.homepage, selectedFiles) + FileSelectionOverlayBar(GalleryType.homepage, selectedFiles!) ], ); // return gallery; diff --git a/lib/ui/home/landing_page_widget.dart b/lib/ui/home/landing_page_widget.dart index beed64eb8..71eafd504 100644 --- a/lib/ui/home/landing_page_widget.dart +++ b/lib/ui/home/landing_page_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:io'; @@ -17,7 +17,7 @@ import 'package:photos/ui/common/gradient_button.dart'; import 'package:photos/ui/payment/subscription.dart'; class LandingPageWidget extends StatefulWidget { - const LandingPageWidget({Key key}) : super(key: key); + const LandingPageWidget({Key? key}) : super(key: key); @override State createState() => _LandingPageWidgetState(); @@ -240,7 +240,7 @@ class FeatureItemWidget extends StatelessWidget { this.featureTitleFirstLine, this.featureTitleSecondLine, this.subText, { - Key key, + Key? key, }) : super(key: key); @override diff --git a/lib/ui/home/memories_widget.dart b/lib/ui/home/memories_widget.dart index 5ac7d7ec6..7ffeecc86 100644 --- a/lib/ui/home/memories_widget.dart +++ b/lib/ui/home/memories_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; @@ -14,20 +14,20 @@ import 'package:photos/utils/share_util.dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; class MemoriesWidget extends StatelessWidget { - const MemoriesWidget({Key key}) : super(key: key); + const MemoriesWidget({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return FutureBuilder>( future: MemoriesService.instance.getMemories(), builder: (context, snapshot) { - if (snapshot.hasError || !snapshot.hasData || snapshot.data.isEmpty) { + if (snapshot.hasError || !snapshot.hasData || snapshot.data!.isEmpty) { return const SizedBox.shrink(); } else { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - _buildMemories(snapshot.data), + _buildMemories(snapshot.data!), const Divider(), ], ); @@ -69,17 +69,17 @@ class MemoriesWidget extends StatelessWidget { bool _areMemoriesFromSameYear(Memory first, Memory second) { final firstDate = - DateTime.fromMicrosecondsSinceEpoch(first.file.creationTime); + DateTime.fromMicrosecondsSinceEpoch(first.file.creationTime!); final secondDate = - DateTime.fromMicrosecondsSinceEpoch(second.file.creationTime); + DateTime.fromMicrosecondsSinceEpoch(second.file.creationTime!); return firstDate.year == secondDate.year; } } class MemoryWidget extends StatefulWidget { const MemoryWidget({ - Key key, - @required this.memories, + Key? key, + required this.memories, }) : super(key: key); final List memories; @@ -119,7 +119,7 @@ class _MemoryWidgetState extends State { title, style: Theme.of(context) .textTheme - .subtitle1 + .subtitle1! .copyWith(fontSize: 12), textAlign: TextAlign.center, ), @@ -186,7 +186,7 @@ class _MemoryWidgetState extends State { String _getTitle(Memory memory) { final present = DateTime.now(); - final then = DateTime.fromMicrosecondsSinceEpoch(memory.file.creationTime); + final then = DateTime.fromMicrosecondsSinceEpoch(memory.file.creationTime!); final diffInYears = present.year - then.year; if (diffInYears == 1) { return "1 year ago"; @@ -201,7 +201,7 @@ class FullScreenMemory extends StatefulWidget { final List memories; final int index; - const FullScreenMemory(this.title, this.memories, this.index, {Key key}) + const FullScreenMemory(this.title, this.memories, this.index, {Key? key}) : super(key: key); @override @@ -215,7 +215,7 @@ class _FullScreenMemoryState extends State { // when the top step indicator isn't visible. bool _showCounter = false; bool _showStepIndicator = true; - PageController _pageController; + PageController? _pageController; bool _shouldDisableScroll = false; final GlobalKey shareButtonKey = GlobalKey(); @@ -273,9 +273,9 @@ class _FullScreenMemoryState extends State { ), Text( getFormattedDate( - DateTime.fromMicrosecondsSinceEpoch(file.creationTime), + DateTime.fromMicrosecondsSinceEpoch(file.creationTime!), ), - style: Theme.of(context).textTheme.subtitle1.copyWith( + style: Theme.of(context).textTheme.subtitle1!.copyWith( fontSize: 14, color: Colors.white, ), //same for both themes @@ -328,7 +328,7 @@ class _FullScreenMemoryState extends State { '${_index + 1}/${widget.memories.length}', style: Theme.of(context) .textTheme - .bodyText1 + .bodyText1! .copyWith(color: Colors.white.withOpacity(0.4)), ) : AnimatedOpacity( @@ -338,7 +338,7 @@ class _FullScreenMemoryState extends State { widget.title, style: Theme.of(context) .textTheme - .headline4 + .headline4! .copyWith(color: Colors.white), ), ), diff --git a/lib/ui/home/status_bar_widget.dart b/lib/ui/home/status_bar_widget.dart index bf67a53e5..f7150a94c 100644 --- a/lib/ui/home/status_bar_widget.dart +++ b/lib/ui/home/status_bar_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; @@ -19,18 +19,18 @@ import 'package:photos/utils/navigation_util.dart'; const double kContainerHeight = 36; class StatusBarWidget extends StatefulWidget { - const StatusBarWidget({Key key}) : super(key: key); + const StatusBarWidget({Key? key}) : super(key: key); @override State createState() => _StatusBarWidgetState(); } class _StatusBarWidgetState extends State { - StreamSubscription _subscription; - StreamSubscription _notificationSubscription; + late StreamSubscription _subscription; + late StreamSubscription _notificationSubscription; bool _showStatus = false; bool _showErrorBanner = false; - Error _syncError; + Error? _syncError; @override void initState() { @@ -118,7 +118,7 @@ class _StatusBarWidgetState extends State { } class SyncStatusWidget extends StatefulWidget { - const SyncStatusWidget({Key key}) : super(key: key); + const SyncStatusWidget({Key? key}) : super(key: key); @override State createState() => _SyncStatusWidgetState(); @@ -127,8 +127,8 @@ class SyncStatusWidget extends StatefulWidget { class _SyncStatusWidgetState extends State { static const Duration kSleepDuration = Duration(milliseconds: 3000); - SyncStatusUpdate _event; - StreamSubscription _subscription; + SyncStatusUpdate? _event; + late StreamSubscription _subscription; @override void initState() { @@ -150,17 +150,17 @@ class _SyncStatusWidgetState extends State { @override Widget build(BuildContext context) { final bool isNotOutdatedEvent = _event != null && - (_event.status == SyncStatus.completedBackup || - _event.status == SyncStatus.completedFirstGalleryImport) && - (DateTime.now().microsecondsSinceEpoch - _event.timestamp > + (_event!.status == SyncStatus.completedBackup || + _event!.status == SyncStatus.completedFirstGalleryImport) && + (DateTime.now().microsecondsSinceEpoch - _event!.timestamp > kSleepDuration.inMicroseconds); if (_event == null || isNotOutdatedEvent || //sync error cases are handled in StatusBarWidget - _event.status == SyncStatus.error) { + _event!.status == SyncStatus.error) { return const SizedBox.shrink(); } - if (_event.status == SyncStatus.completedBackup) { + if (_event!.status == SyncStatus.completedBackup) { return const SyncStatusCompletedWidget(); } return RefreshIndicatorWidget(_event); @@ -173,9 +173,9 @@ class RefreshIndicatorWidget extends StatelessWidget { valueColor: AlwaysStoppedAnimation(Color.fromRGBO(45, 194, 98, 1.0)), ); - final SyncStatusUpdate event; + final SyncStatusUpdate? event; - const RefreshIndicatorWidget(this.event, {Key key}) : super(key: key); + const RefreshIndicatorWidget(this.event, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -211,30 +211,30 @@ class RefreshIndicatorWidget extends StatelessWidget { } String _getRefreshingText() { - if (event.status == SyncStatus.startedFirstGalleryImport || - event.status == SyncStatus.completedFirstGalleryImport) { + if (event!.status == SyncStatus.startedFirstGalleryImport || + event!.status == SyncStatus.completedFirstGalleryImport) { return "Loading gallery..."; } - if (event.status == SyncStatus.applyingRemoteDiff) { + if (event!.status == SyncStatus.applyingRemoteDiff) { return "Syncing..."; } - if (event.status == SyncStatus.preparingForUpload) { + if (event!.status == SyncStatus.preparingForUpload) { return "Encrypting backup..."; } - if (event.status == SyncStatus.inProgress) { - return event.completed.toString() + + if (event!.status == SyncStatus.inProgress) { + return event!.completed.toString() + "/" + - event.total.toString() + + event!.total.toString() + " memories preserved"; } - if (event.status == SyncStatus.paused) { - return event.reason; + if (event!.status == SyncStatus.paused) { + return event!.reason; } - if (event.status == SyncStatus.error) { - return event.reason ?? "Upload failed"; + if (event!.status == SyncStatus.error) { + return event!.reason ?? "Upload failed"; } - if (event.status == SyncStatus.completedBackup) { - if (event.wasStopped) { + if (event!.status == SyncStatus.completedBackup) { + if (event!.wasStopped) { return "Sync stopped"; } } @@ -243,7 +243,7 @@ class RefreshIndicatorWidget extends StatelessWidget { } class BrandingWidget extends StatelessWidget { - const BrandingWidget({Key key}) : super(key: key); + const BrandingWidget({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -271,7 +271,7 @@ class BrandingWidget extends StatelessWidget { } class SyncStatusCompletedWidget extends StatelessWidget { - const SyncStatusCompletedWidget({Key key}) : super(key: key); + const SyncStatusCompletedWidget({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 72b9d95c5..2584fb22d 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; import 'dart:io'; @@ -51,7 +51,7 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import 'package:uni_links/uni_links.dart'; class HomeWidget extends StatefulWidget { - const HomeWidget({Key key}) : super(key: key); + const HomeWidget({Key? key}) : super(key: key); @override State createState() => _HomeWidgetState(); @@ -74,17 +74,17 @@ class _HomeWidgetState extends State { // for receiving media files // ignore: unused_field - StreamSubscription _intentDataStreamSubscription; - List _sharedFiles; + StreamSubscription? _intentDataStreamSubscription; + List? _sharedFiles; - StreamSubscription _tabChangedEventSubscription; - StreamSubscription _subscriptionPurchaseEvent; - StreamSubscription _triggerLogoutEvent; - StreamSubscription _loggedOutEvent; - StreamSubscription _permissionGrantedEvent; - StreamSubscription _firstImportEvent; - StreamSubscription _backupFoldersUpdatedEvent; - StreamSubscription _accountConfiguredEvent; + late StreamSubscription _tabChangedEventSubscription; + late StreamSubscription _subscriptionPurchaseEvent; + late StreamSubscription _triggerLogoutEvent; + late StreamSubscription _loggedOutEvent; + late StreamSubscription _permissionGrantedEvent; + late StreamSubscription _firstImportEvent; + late StreamSubscription _backupFoldersUpdatedEvent; + late StreamSubscription _accountConfiguredEvent; @override void initState() { @@ -323,7 +323,7 @@ class _HomeWidgetState extends State { if (UserRemoteFlagService.instance.showPasswordReminder()) { return const PasswordReminder(); } - if (_sharedFiles != null && _sharedFiles.isNotEmpty) { + if (_sharedFiles != null && _sharedFiles!.isNotEmpty) { ReceiveSharingIntent.reset(); return CreateCollectionPage(null, _sharedFiles); } @@ -392,7 +392,7 @@ class _HomeWidgetState extends State { Future _initDeepLinks() async { // Platform messages may fail, so we use a try/catch PlatformException. try { - final String initialLink = await getInitialLink(); + final String? initialLink = await getInitialLink(); // Parse the link and warn the user, if it is not correct, // but keep in mind it could be `null`. if (initialLink != null) { @@ -410,8 +410,8 @@ class _HomeWidgetState extends State { // Attach a listener to the stream linkStream.listen( - (String link) { - _logger.info("Link received: " + link); + (String? link) { + _logger.info("Link received: " + link!); _getCredentials(context, link); }, onError: (err) { @@ -421,11 +421,11 @@ class _HomeWidgetState extends State { return false; } - void _getCredentials(BuildContext context, String link) { + void _getCredentials(BuildContext context, String? link) { if (Configuration.instance.hasConfiguredAccount()) { return; } - final ott = Uri.parse(link).queryParameters["ott"]; + final ott = Uri.parse(link!).queryParameters["ott"]!; UserService.instance.verifyEmail(context, ott); } diff --git a/lib/ui/huge_listview/draggable_scrollbar.dart b/lib/ui/huge_listview/draggable_scrollbar.dart index 7626670d4..4221396e6 100644 --- a/lib/ui/huge_listview/draggable_scrollbar.dart +++ b/lib/ui/huge_listview/draggable_scrollbar.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:async'; import 'package:flutter/foundation.dart'; @@ -12,18 +10,18 @@ class DraggableScrollbar extends StatefulWidget { final Color backgroundColor; final Color drawColor; final double heightScrollThumb; - final EdgeInsetsGeometry padding; + final EdgeInsetsGeometry? padding; final int totalCount; final int initialScrollIndex; final double bottomSafeArea; final int currentFirstIndex; - final ValueChanged onChange; + final ValueChanged? onChange; final String Function(int) labelTextBuilder; final bool isEnabled; const DraggableScrollbar({ - Key key, - @required this.child, + Key? key, + required this.child, this.backgroundColor = Colors.white, this.drawColor = Colors.grey, this.heightScrollThumb = 80.0, @@ -32,7 +30,7 @@ class DraggableScrollbar extends StatefulWidget { this.totalCount = 1, this.initialScrollIndex = 0, this.currentFirstIndex = 0, - @required this.labelTextBuilder, + required this.labelTextBuilder, this.onChange, this.isEnabled = true, }) : super(key: key); @@ -47,18 +45,18 @@ class DraggableScrollbarState extends State static const labelAnimationDuration = Duration(milliseconds: 1000); double thumbOffset = 0.0; bool isDragging = false; - int currentFirstIndex; + late int currentFirstIndex; double get thumbMin => 0.0; double get thumbMax => - context.size.height - widget.heightScrollThumb - widget.bottomSafeArea; + context.size!.height - widget.heightScrollThumb - widget.bottomSafeArea; - AnimationController _thumbAnimationController; - Animation _thumbAnimation; - AnimationController _labelAnimationController; - Animation _labelAnimation; - Timer _fadeoutTimer; + late AnimationController _thumbAnimationController; + Animation? _thumbAnimation; + late AnimationController _labelAnimationController; + Animation? _labelAnimation; + Timer? _fadeoutTimer; @override void initState() { @@ -66,7 +64,7 @@ class DraggableScrollbarState extends State currentFirstIndex = widget.currentFirstIndex; if (widget.initialScrollIndex > 0 && widget.totalCount > 1) { - WidgetsBinding.instance?.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { setState( () => thumbOffset = (widget.initialScrollIndex / widget.totalCount) * (thumbMax - thumbMin), @@ -130,7 +128,7 @@ class DraggableScrollbarState extends State } Widget buildThumb() => Padding( - padding: widget.padding, + padding: widget.padding!, child: Container( alignment: Alignment.topRight, margin: EdgeInsets.only(top: thumbOffset), diff --git a/lib/ui/huge_listview/huge_listview.dart b/lib/ui/huge_listview/huge_listview.dart index 9bb16cf18..71ceda27c 100644 --- a/lib/ui/huge_listview/huge_listview.dart +++ b/lib/ui/huge_listview/huge_listview.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:math' show max; @@ -17,7 +17,7 @@ typedef HugeListViewErrorBuilder = Widget Function( class HugeListView extends StatefulWidget { /// A [ScrollablePositionedList] controller for jumping or scrolling to an item. - final ItemScrollController controller; + final ItemScrollController? controller; /// Index of an item to initially align within the viewport. final int startIndex; @@ -46,29 +46,29 @@ class HugeListView extends StatefulWidget { final HugeListViewItemBuilder itemBuilder; /// Called to build a progress widget while the whole list is initialized. - final WidgetBuilder waitBuilder; + final WidgetBuilder? waitBuilder; /// Called to build a widget when the list is empty. - final WidgetBuilder emptyResultBuilder; + final WidgetBuilder? emptyResultBuilder; /// Called to build a widget when there is an error. - final HugeListViewErrorBuilder errorBuilder; + final HugeListViewErrorBuilder? errorBuilder; /// Event to call with the index of the topmost visible item in the viewport while scrolling. /// Can be used to display the current letter of an alphabetically sorted list, for instance. - final ValueChanged firstShown; + final ValueChanged? firstShown; final bool isDraggableScrollbarEnabled; - final EdgeInsetsGeometry thumbPadding; + final EdgeInsetsGeometry? thumbPadding; const HugeListView({ - Key key, + Key? key, this.controller, - @required this.startIndex, - @required this.totalCount, - @required this.labelTextBuilder, - @required this.itemBuilder, + required this.startIndex, + required this.totalCount, + required this.labelTextBuilder, + required this.itemBuilder, this.waitBuilder, this.emptyResultBuilder, this.errorBuilder, @@ -121,13 +121,13 @@ class HugeListViewState extends State> { @override Widget build(BuildContext context) { if (error != null && widget.errorBuilder != null) { - return widget.errorBuilder(context, error); + return widget.errorBuilder!(context, error); } if (widget.totalCount == -1 && widget.waitBuilder != null) { - return widget.waitBuilder(context); + return widget.waitBuilder!(context); } if (widget.totalCount == 0 && widget.emptyResultBuilder != null) { - return widget.emptyResultBuilder(context); + return widget.emptyResultBuilder!(context); } return LayoutBuilder( diff --git a/lib/ui/huge_listview/lazy_loading_gallery.dart b/lib/ui/huge_listview/lazy_loading_gallery.dart index 3250f73ff..7f7258525 100644 --- a/lib/ui/huge_listview/lazy_loading_gallery.dart +++ b/lib/ui/huge_listview/lazy_loading_gallery.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; import 'dart:math'; @@ -25,16 +25,16 @@ import 'package:photos/utils/navigation_util.dart'; import 'package:visibility_detector/visibility_detector.dart'; class LazyLoadingGallery extends StatefulWidget { - final List files; + final List files; final int index; - final Stream reloadEvent; + final Stream? reloadEvent; final Set removalEventTypes; final GalleryLoader asyncLoader; - final SelectedFiles selectedFiles; + final SelectedFiles? selectedFiles; final String tag; - final String logTag; + final String? logTag; final Stream currentIndexStream; - final int photoGirdSize; + final int? photoGirdSize; LazyLoadingGallery( this.files, @@ -47,7 +47,7 @@ class LazyLoadingGallery extends StatefulWidget { this.currentIndexStream, { this.logTag = "", this.photoGirdSize = photoGridSizeDefault, - Key key, + Key? key, }) : super(key: key ?? UniqueKey()); @override @@ -58,12 +58,12 @@ class _LazyLoadingGalleryState extends State { static const kRecycleLimit = 400; static const kNumberOfDaysToRenderBeforeAndAfter = 8; - Logger _logger; + late Logger _logger; - List _files; - StreamSubscription _reloadEventSubscription; - StreamSubscription _currentIndexSubscription; - bool _shouldRender; + List? _files; + late StreamSubscription _reloadEventSubscription; + late StreamSubscription _currentIndexSubscription; + bool? _shouldRender; final ValueNotifier _toggleSelectAllFromDay = ValueNotifier(false); final ValueNotifier _showSelectAllButton = ValueNotifier(false); final ValueNotifier _areAllFromDaySelected = ValueNotifier(false); @@ -71,7 +71,7 @@ class _LazyLoadingGalleryState extends State { @override void initState() { //this is for removing the 'select all from day' icon on unselecting all files with 'cancel' - widget.selectedFiles.addListener(_selectedFilesListener); + widget.selectedFiles!.addListener(_selectedFilesListener); super.initState(); _init(); } @@ -80,7 +80,7 @@ class _LazyLoadingGalleryState extends State { _logger = Logger("LazyLoading_${widget.logTag}"); _shouldRender = true; _files = widget.files; - _reloadEventSubscription = widget.reloadEvent.listen((e) => _onReload(e)); + _reloadEventSubscription = widget.reloadEvent!.listen((e) => _onReload(e)); _currentIndexSubscription = widget.currentIndexStream.listen((currentIndex) { @@ -96,9 +96,9 @@ class _LazyLoadingGalleryState extends State { Future _onReload(FilesUpdatedEvent event) async { final galleryDate = - DateTime.fromMicrosecondsSinceEpoch(_files[0].creationTime); + DateTime.fromMicrosecondsSinceEpoch(_files![0]!.creationTime!); final filesUpdatedThisDay = event.updatedFiles.where((file) { - final fileDate = DateTime.fromMicrosecondsSinceEpoch(file.creationTime); + final fileDate = DateTime.fromMicrosecondsSinceEpoch(file.creationTime!); return fileDate.year == galleryDate.year && fileDate.month == galleryDate.month && fileDate.day == galleryDate.day; @@ -125,8 +125,8 @@ class _LazyLoadingGalleryState extends State { } } else if (widget.removalEventTypes.contains(event.type)) { // Files were removed - final generatedFileIDs = {}; - final uploadedFileIds = {}; + final generatedFileIDs = {}; + final uploadedFileIds = {}; for (final file in filesUpdatedThisDay) { if (file.generatedID != null) { generatedFileIDs.add(file.generatedID); @@ -134,16 +134,16 @@ class _LazyLoadingGalleryState extends State { uploadedFileIds.add(file.uploadedFileID); } } - final List files = []; - files.addAll(_files); + final List files = []; + files.addAll(_files!); files.removeWhere( (file) => - generatedFileIDs.contains(file.generatedID) || + generatedFileIDs.contains(file!.generatedID) || uploadedFileIds.contains(file.uploadedFileID), ); if (kDebugMode) { _logger.finest( - "removed ${_files.length - files.length} due to ${event.reason}", + "removed ${_files!.length - files.length} due to ${event.reason}", ); } if (mounted) { @@ -163,7 +163,7 @@ class _LazyLoadingGalleryState extends State { void dispose() { _reloadEventSubscription.cancel(); _currentIndexSubscription.cancel(); - widget.selectedFiles.removeListener(_selectedFilesListener); + widget.selectedFiles!.removeListener(_selectedFilesListener); _toggleSelectAllFromDay.dispose(); _showSelectAllButton.dispose(); _areAllFromDaySelected.dispose(); @@ -181,7 +181,7 @@ class _LazyLoadingGalleryState extends State { @override Widget build(BuildContext context) { - if (_files.isEmpty) { + if (_files!.isEmpty) { return const SizedBox.shrink(); } return Column( @@ -191,12 +191,12 @@ class _LazyLoadingGalleryState extends State { children: [ getDayWidget( context, - _files[0].creationTime, - widget.photoGirdSize, + _files![0]!.creationTime!, + widget.photoGirdSize!, ), ValueListenableBuilder( valueListenable: _showSelectAllButton, - builder: (context, value, _) { + builder: (context, dynamic value, _) { return !value ? const SizedBox.shrink() : GestureDetector( @@ -206,7 +206,7 @@ class _LazyLoadingGalleryState extends State { height: 44, child: ValueListenableBuilder( valueListenable: _areAllFromDaySelected, - builder: (context, value, _) { + builder: (context, dynamic value, _) { return value ? const Icon( Icons.check_circle, @@ -232,11 +232,11 @@ class _LazyLoadingGalleryState extends State { ) ], ), - _shouldRender + _shouldRender! ? _getGallery() : PlaceHolderWidget( - _files.length, - widget.photoGirdSize, + _files!.length, + widget.photoGirdSize!, ), ], ); @@ -244,21 +244,21 @@ class _LazyLoadingGalleryState extends State { Widget _getGallery() { final List childGalleries = []; - final subGalleryItemLimit = widget.photoGirdSize < photoGridSizeDefault + final subGalleryItemLimit = widget.photoGirdSize! < photoGridSizeDefault ? subGalleryLimitMin : subGalleryLimitDefault; - for (int index = 0; index < _files.length; index += subGalleryItemLimit) { + for (int index = 0; index < _files!.length; index += subGalleryItemLimit) { childGalleries.add( LazyLoadingGridView( widget.tag, - _files.sublist( + _files!.sublist( index, - min(index + subGalleryItemLimit, _files.length), + min(index + subGalleryItemLimit, _files!.length), ), widget.asyncLoader, widget.selectedFiles, index == 0, - _files.length > kRecycleLimit, + _files!.length > kRecycleLimit, _toggleSelectAllFromDay, _areAllFromDaySelected, widget.photoGirdSize, @@ -272,7 +272,7 @@ class _LazyLoadingGalleryState extends State { } void _selectedFilesListener() { - if (widget.selectedFiles.files.isEmpty) { + if (widget.selectedFiles!.files.isEmpty) { _showSelectAllButton.value = false; } else { _showSelectAllButton.value = true; @@ -282,14 +282,14 @@ class _LazyLoadingGalleryState extends State { class LazyLoadingGridView extends StatefulWidget { final String tag; - final List filesInDay; + final List filesInDay; final GalleryLoader asyncLoader; - final SelectedFiles selectedFiles; + final SelectedFiles? selectedFiles; final bool shouldRender; final bool shouldRecycle; final ValueNotifier toggleSelectAllFromDay; final ValueNotifier areAllFilesSelected; - final int photoGridSize; + final int? photoGridSize; LazyLoadingGridView( this.tag, @@ -301,7 +301,7 @@ class LazyLoadingGridView extends StatefulWidget { this.toggleSelectAllFromDay, this.areAllFilesSelected, this.photoGridSize, { - Key key, + Key? key, }) : super(key: key ?? UniqueKey()); @override @@ -309,15 +309,15 @@ class LazyLoadingGridView extends StatefulWidget { } class _LazyLoadingGridViewState extends State { - bool _shouldRender; - int _currentUserID; - StreamSubscription _clearSelectionsEvent; + bool? _shouldRender; + int? _currentUserID; + late StreamSubscription _clearSelectionsEvent; @override void initState() { _shouldRender = widget.shouldRender; _currentUserID = Configuration.instance.getUserID(); - widget.selectedFiles.addListener(_selectedFilesListener); + widget.selectedFiles!.addListener(_selectedFilesListener); _clearSelectionsEvent = Bus.instance.on().listen((event) { if (mounted) { @@ -330,7 +330,7 @@ class _LazyLoadingGridViewState extends State { @override void dispose() { - widget.selectedFiles.removeListener(_selectedFilesListener); + widget.selectedFiles!.removeListener(_selectedFilesListener); _clearSelectionsEvent.cancel(); widget.toggleSelectAllFromDay .removeListener(_toggleSelectAllFromDayListener); @@ -365,25 +365,25 @@ class _LazyLoadingGridViewState extends State { }); } }, - child: _shouldRender + child: _shouldRender! ? _getGridView() - : PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), + : PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize!), ); } Widget _getNonRecyclableView() { - if (!_shouldRender) { + if (!_shouldRender!) { return VisibilityDetector( key: UniqueKey(), onVisibilityChanged: (visibility) { - if (mounted && visibility.visibleFraction > 0 && !_shouldRender) { + if (mounted && visibility.visibleFraction > 0 && !_shouldRender!) { setState(() { _shouldRender = true; }); } }, child: - PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize), + PlaceHolderWidget(widget.filesInDay.length, widget.photoGridSize!), ); } else { return _getGridView(); @@ -396,34 +396,34 @@ class _LazyLoadingGridViewState extends State { physics: const NeverScrollableScrollPhysics(), // to disable GridView's scrolling itemBuilder: (context, index) { - return _buildFile(context, widget.filesInDay[index]); + return _buildFile(context, widget.filesInDay[index]!); }, itemCount: widget.filesInDay.length, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisSpacing: 2, mainAxisSpacing: 2, - crossAxisCount: widget.photoGridSize, + crossAxisCount: widget.photoGridSize!, ), padding: const EdgeInsets.all(0), ); } Widget _buildFile(BuildContext context, File file) { - final isFileSelected = widget.selectedFiles.isFileSelected(file); + final isFileSelected = widget.selectedFiles!.isFileSelected(file); Color selectionColor = Colors.white; if (isFileSelected && file.isUploaded && (file.ownerID != _currentUserID || - file.pubMagicMetadata.uploaderName != null)) { + file.pubMagicMetadata!.uploaderName != null)) { final avatarColors = getEnteColorScheme(context).avatarColors; final int randomID = file.ownerID != _currentUserID - ? file.ownerID - : file.pubMagicMetadata.uploaderName.sumAsciiValues; + ? file.ownerID! + : file.pubMagicMetadata!.uploaderName.sumAsciiValues; selectionColor = avatarColors[(randomID).remainder(avatarColors.length)]; } return GestureDetector( onTap: () { - if (widget.selectedFiles.files.isNotEmpty) { + if (widget.selectedFiles!.files.isNotEmpty) { _selectFile(file); } else { _routeToDetailPage(file, context); @@ -452,7 +452,7 @@ class _LazyLoadingGridViewState extends State { serverLoadDeferDuration: thumbnailServerLoadDeferDuration, shouldShowLivePhotoOverlay: true, key: Key(widget.tag + file.tag), - thumbnailSize: widget.photoGridSize < photoGridSizeDefault + thumbnailSize: widget.photoGridSize! < photoGridSizeDefault ? thumbnailLargeSize : thumbnailSmallSize, shouldShowOwnerAvatar: !isFileSelected, @@ -478,7 +478,7 @@ class _LazyLoadingGridViewState extends State { } void _selectFile(File file) { - widget.selectedFiles.toggleSelection(file); + widget.selectedFiles!.toggleSelection(file); } void _routeToDetailPage(File file, BuildContext context) { @@ -494,14 +494,14 @@ class _LazyLoadingGridViewState extends State { } void _selectedFilesListener() { - if (widget.selectedFiles.files.containsAll(widget.filesInDay.toSet())) { + if (widget.selectedFiles!.files.containsAll(widget.filesInDay.toSet())) { widget.areAllFilesSelected.value = true; } else { widget.areAllFilesSelected.value = false; } bool shouldRefresh = false; for (final file in widget.filesInDay) { - if (widget.selectedFiles.isPartOfLastSelected(file)) { + if (widget.selectedFiles!.isPartOfLastSelected(file!)) { shouldRefresh = true; } } @@ -511,12 +511,12 @@ class _LazyLoadingGridViewState extends State { } void _toggleSelectAllFromDayListener() { - if (widget.selectedFiles.files.containsAll(widget.filesInDay.toSet())) { + if (widget.selectedFiles!.files.containsAll(widget.filesInDay.toSet())) { setState(() { - widget.selectedFiles.unSelectAll(widget.filesInDay.toSet()); + widget.selectedFiles!.unSelectAll(widget.filesInDay.toSet() as Set); }); } else { - widget.selectedFiles.selectAll(widget.filesInDay.toSet()); + widget.selectedFiles!.selectAll(widget.filesInDay.toSet() as Set); } } } diff --git a/lib/ui/huge_listview/scroll_bar_thumb.dart b/lib/ui/huge_listview/scroll_bar_thumb.dart index dfd8ea8f7..8e7212cc8 100644 --- a/lib/ui/huge_listview/scroll_bar_thumb.dart +++ b/lib/ui/huge_listview/scroll_bar_thumb.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'package:flutter/material.dart'; @@ -7,8 +7,8 @@ class ScrollBarThumb extends StatelessWidget { final Color drawColor; final double height; final String title; - final Animation labelAnimation; - final Animation thumbAnimation; + final Animation? labelAnimation; + final Animation? thumbAnimation; final Function(DragStartDetails details) onDragStart; final Function(DragUpdateDetails details) onDragUpdate; final Function(DragEndDetails details) onDragEnd; @@ -23,7 +23,7 @@ class ScrollBarThumb extends StatelessWidget { this.onDragStart, this.onDragUpdate, this.onDragEnd, { - Key key, + Key? key, }) : super(key: key); @override @@ -33,7 +33,7 @@ class ScrollBarThumb extends StatelessWidget { children: [ IgnorePointer( child: FadeTransition( - opacity: labelAnimation, + opacity: labelAnimation as Animation, child: Container( padding: const EdgeInsets.fromLTRB(20, 12, 20, 12), decoration: BoxDecoration( @@ -60,7 +60,7 @@ class ScrollBarThumb extends StatelessWidget { onVerticalDragUpdate: onDragUpdate, onVerticalDragEnd: onDragEnd, child: SlideFadeTransition( - animation: thumbAnimation, + animation: thumbAnimation as Animation?, child: CustomPaint( foregroundPainter: _ArrowCustomPainter(drawColor), child: Material( @@ -131,27 +131,27 @@ class _ArrowCustomPainter extends CustomPainter { } class SlideFadeTransition extends StatelessWidget { - final Animation animation; + final Animation? animation; final Widget child; const SlideFadeTransition({ - Key key, - @required this.animation, - @required this.child, + Key? key, + required this.animation, + required this.child, }) : super(key: key); @override Widget build(BuildContext context) { return AnimatedBuilder( - animation: animation, - builder: (context, child) => animation.value == 0.0 ? Container() : child, + animation: animation!, + builder: (context, child) => animation!.value == 0.0 ? Container() : child!, child: SlideTransition( position: Tween( begin: const Offset(0.3, 0.0), end: const Offset(0.0, 0.0), - ).animate(animation), + ).animate(animation!), child: FadeTransition( - opacity: animation, + opacity: animation!, child: child, ), ), diff --git a/lib/ui/lifecycle_event_handler.dart b/lib/ui/lifecycle_event_handler.dart index 3f54c3438..da539f074 100644 --- a/lib/ui/lifecycle_event_handler.dart +++ b/lib/ui/lifecycle_event_handler.dart @@ -1,11 +1,11 @@ -// @dart=2.9 + import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; class LifecycleEventHandler extends WidgetsBindingObserver { - final AsyncCallback resumeCallBack; - final AsyncCallback suspendingCallBack; + final AsyncCallback? resumeCallBack; + final AsyncCallback? suspendingCallBack; LifecycleEventHandler({ this.resumeCallBack, @@ -17,14 +17,14 @@ class LifecycleEventHandler extends WidgetsBindingObserver { switch (state) { case AppLifecycleState.resumed: if (resumeCallBack != null) { - await resumeCallBack(); + await resumeCallBack!(); } break; case AppLifecycleState.inactive: case AppLifecycleState.paused: case AppLifecycleState.detached: if (suspendingCallBack != null) { - await suspendingCallBack(); + await suspendingCallBack!(); } break; } diff --git a/lib/ui/loading_photos_widget.dart b/lib/ui/loading_photos_widget.dart index 51ae17ef9..0f52c8846 100644 --- a/lib/ui/loading_photos_widget.dart +++ b/lib/ui/loading_photos_widget.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + import 'dart:async'; import 'dart:io'; @@ -15,15 +15,15 @@ import 'package:photos/ui/common/bottom_shadow.dart'; import 'package:photos/utils/navigation_util.dart'; class LoadingPhotosWidget extends StatefulWidget { - const LoadingPhotosWidget({Key key}) : super(key: key); + const LoadingPhotosWidget({Key? key}) : super(key: key); @override State createState() => _LoadingPhotosWidgetState(); } class _LoadingPhotosWidgetState extends State { - StreamSubscription _firstImportEvent; - StreamSubscription _imprortProgressEvent; + late StreamSubscription _firstImportEvent; + late StreamSubscription _imprortProgressEvent; int _currentPage = 0; String _loadingMessage = "Loading your photos..."; final PageController _pageController = PageController( @@ -145,7 +145,7 @@ class _LoadingPhotosWidgetState extends State { children: [ Text( "Did you know?", - style: Theme.of(context).textTheme.headline6.copyWith( + style: Theme.of(context).textTheme.headline6!.copyWith( color: Theme.of(context).colorScheme.greenText, ), ), @@ -192,7 +192,7 @@ class _LoadingPhotosWidgetState extends State { textAlign: TextAlign.start, style: Theme.of(context) .textTheme - .headline5 + .headline5! .copyWith(color: Theme.of(context).colorScheme.defaultTextColor), ); } diff --git a/lib/ui/nav_bar.dart b/lib/ui/nav_bar.dart index a7699ef5a..56be7937a 100644 --- a/lib/ui/nav_bar.dart +++ b/lib/ui/nav_bar.dart @@ -1,4 +1,4 @@ -// @dart=2.9 + library google_nav_bar; @@ -7,7 +7,7 @@ import 'package:flutter/services.dart'; class GNav extends StatefulWidget { const GNav({ - Key key, + Key? key, this.tabs, this.selectedIndex = 0, this.onTabChange, @@ -34,29 +34,29 @@ class GNav extends StatefulWidget { this.mainAxisAlignment = MainAxisAlignment.spaceBetween, }) : super(key: key); - final List tabs; + final List? tabs; final int selectedIndex; - final Function onTabChange; - final double gap; - final double tabBorderRadius; - final double iconSize; - final Color activeColor; - final Color backgroundColor; - final Color tabBackgroundColor; - final Color color; - final Color rippleColor; - final Color hoverColor; - final EdgeInsetsGeometry padding; - final EdgeInsetsGeometry tabMargin; - final TextStyle textStyle; - final Duration duration; - final Curve curve; - final bool debug; - final bool haptic; - final Border tabBorder; - final Border tabActiveBorder; - final List tabShadow; - final Gradient tabBackgroundGradient; + final Function? onTabChange; + final double? gap; + final double? tabBorderRadius; + final double? iconSize; + final Color? activeColor; + final Color? backgroundColor; + final Color? tabBackgroundColor; + final Color? color; + final Color? rippleColor; + final Color? hoverColor; + final EdgeInsetsGeometry? padding; + final EdgeInsetsGeometry? tabMargin; + final TextStyle? textStyle; + final Duration? duration; + final Curve? curve; + final bool? debug; + final bool? haptic; + final Border? tabBorder; + final Border? tabActiveBorder; + final List? tabShadow; + final Gradient? tabBackgroundGradient; final MainAxisAlignment mainAxisAlignment; @override @@ -64,7 +64,7 @@ class GNav extends StatefulWidget { } class _GNavState extends State { - int selectedIndex; + int? selectedIndex; bool clickable = true; @override @@ -83,20 +83,20 @@ class _GNavState extends State { color: widget.backgroundColor ?? Colors.transparent, child: Row( mainAxisAlignment: widget.mainAxisAlignment, - children: widget.tabs + children: widget.tabs! .map( (t) => GButton( key: t.key, border: t.border ?? widget.tabBorder, activeBorder: t.activeBorder ?? widget.tabActiveBorder, - borderRadius: t.borderRadius ?? widget.tabBorderRadius != null + borderRadius: t.borderRadius as bool? ?? widget.tabBorderRadius != null ? BorderRadius.all( - Radius.circular(widget.tabBorderRadius), + Radius.circular(widget.tabBorderRadius!), ) : const BorderRadius.all(Radius.circular(100.0)), debug: widget.debug ?? false, margin: t.margin ?? widget.tabMargin, - active: selectedIndex == widget.tabs.indexOf(t), + active: selectedIndex == widget.tabs!.indexOf(t), gap: t.gap ?? widget.gap, iconActiveColor: t.iconActiveColor ?? widget.activeColor, iconColor: t.iconColor ?? widget.color, @@ -118,7 +118,7 @@ class _GNavState extends State { Colors.transparent, duration: widget.duration ?? const Duration(milliseconds: 500), onPressed: () { - widget.onTabChange(widget.tabs.indexOf(t)); + widget.onTabChange!(widget.tabs!.indexOf(t)); }, ), ) @@ -129,35 +129,35 @@ class _GNavState extends State { } class GButton extends StatefulWidget { - final bool active; - final bool debug; - final bool haptic; - final double gap; - final Color iconColor; - final Color rippleColor; - final Color hoverColor; - final Color iconActiveColor; - final Color textColor; - final EdgeInsetsGeometry padding; - final EdgeInsetsGeometry margin; - final TextStyle textStyle; - final double iconSize; - final Function onPressed; + final bool? active; + final bool? debug; + final bool? haptic; + final double? gap; + final Color? iconColor; + final Color? rippleColor; + final Color? hoverColor; + final Color? iconActiveColor; + final Color? textColor; + final EdgeInsetsGeometry? padding; + final EdgeInsetsGeometry? margin; + final TextStyle? textStyle; + final double? iconSize; + final Function? onPressed; final String text; - final IconData icon; - final Color backgroundColor; - final Duration duration; - final Curve curve; - final Gradient backgroundGradient; - final Widget leading; - final BorderRadius borderRadius; - final Border border; - final Border activeBorder; - final List shadow; - final String semanticLabel; + final IconData? icon; + final Color? backgroundColor; + final Duration? duration; + final Curve? curve; + final Gradient? backgroundGradient; + final Widget? leading; + final BorderRadius? borderRadius; + final Border? border; + final Border? activeBorder; + final List? shadow; + final String? semanticLabel; const GButton({ - Key key, + Key? key, this.active, this.haptic, this.backgroundColor, @@ -205,8 +205,8 @@ class _GButtonState extends State { iconSize: widget.iconSize, active: widget.active, onPressed: () { - if (widget.haptic) HapticFeedback.selectionClick(); - widget.onPressed(); + if (widget.haptic!) HapticFeedback.selectionClick(); + widget.onPressed!(); }, padding: widget.padding, margin: widget.margin, @@ -227,7 +227,7 @@ class _GButtonState extends State { class Button extends StatefulWidget { const Button({ - Key key, + Key? key, this.icon, this.iconSize, this.leading, @@ -252,38 +252,38 @@ class Button extends StatefulWidget { this.shadow, }) : super(key: key); - final IconData icon; - final double iconSize; - final Text text; - final Widget leading; - final Color iconActiveColor; - final Color iconColor; - final Color color; - final Color rippleColor; - final Color hoverColor; - final double gap; - final bool active; - final bool debug; - final VoidCallback onPressed; - final EdgeInsetsGeometry padding; - final EdgeInsetsGeometry margin; - final Duration duration; - final Curve curve; - final Gradient gradient; - final BorderRadius borderRadius; - final Border border; - final Border activeBorder; - final List shadow; + final IconData? icon; + final double? iconSize; + final Text? text; + final Widget? leading; + final Color? iconActiveColor; + final Color? iconColor; + final Color? color; + final Color? rippleColor; + final Color? hoverColor; + final double? gap; + final bool? active; + final bool? debug; + final VoidCallback? onPressed; + final EdgeInsetsGeometry? padding; + final EdgeInsetsGeometry? margin; + final Duration? duration; + final Curve? curve; + final Gradient? gradient; + final BorderRadius? borderRadius; + final Border? border; + final Border? activeBorder; + final List? shadow; @override State