NullSafety migration: app_lock.dart
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:ente_auth/l10n/l10n.dart';
|
||||
import 'package:ente_auth/locale.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
/// A widget which handles app lifecycle events for showing and hiding a lock screen.
|
||||
/// This should wrap around a `MyApp` widget (or equivalent).
|
||||
@@ -30,26 +27,28 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
// ignore_for_file: unnecessary_this, library_private_types_in_public_api
|
||||
class AppLock extends StatefulWidget {
|
||||
final Widget Function(Object) builder;
|
||||
final Widget Function(Object?) builder;
|
||||
final Widget lockScreen;
|
||||
final bool enabled;
|
||||
final Duration backgroundLockLatency;
|
||||
final ThemeData darkTheme;
|
||||
final ThemeData lightTheme;
|
||||
final ThemeData? darkTheme;
|
||||
final ThemeData? lightTheme;
|
||||
final ThemeMode savedThemeMode;
|
||||
final Locale locale;
|
||||
|
||||
const AppLock({
|
||||
Key key,
|
||||
@required this.builder,
|
||||
@required this.lockScreen,
|
||||
Key? key,
|
||||
required this.builder,
|
||||
required this.lockScreen,
|
||||
required this.savedThemeMode,
|
||||
this.enabled = true,
|
||||
this.locale = const Locale('en', 'US'),
|
||||
this.backgroundLockLatency = const Duration(seconds: 0),
|
||||
this.darkTheme,
|
||||
this.lightTheme,
|
||||
this.locale,
|
||||
}) : super(key: key);
|
||||
|
||||
static _AppLockState of(BuildContext context) =>
|
||||
static _AppLockState? of(BuildContext context) =>
|
||||
context.findAncestorStateOfType<_AppLockState>();
|
||||
|
||||
@override
|
||||
@@ -59,11 +58,11 @@ class AppLock extends StatefulWidget {
|
||||
class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
|
||||
static final GlobalKey<NavigatorState> _navigatorKey = GlobalKey();
|
||||
|
||||
bool _didUnlockForAppLaunch;
|
||||
bool _isLocked;
|
||||
bool _enabled;
|
||||
late bool _didUnlockForAppLaunch;
|
||||
late bool _isLocked;
|
||||
late bool _enabled;
|
||||
|
||||
Timer _backgroundLockLatencyTimer;
|
||||
Timer? _backgroundLockLatencyTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -109,17 +108,14 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
|
||||
return MaterialApp(
|
||||
home: this.widget.enabled ? this._lockScreen : this.widget.builder(null),
|
||||
navigatorKey: _navigatorKey,
|
||||
themeMode: ThemeMode.system,
|
||||
themeMode: widget.savedThemeMode,
|
||||
theme: widget.lightTheme,
|
||||
darkTheme: widget.darkTheme,
|
||||
locale: widget.locale,
|
||||
supportedLocales: appSupportedLocales,
|
||||
localeListResolutionCallback: localResolutionCallBack,
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
...AppLocalizations.localizationsDelegates,
|
||||
],
|
||||
onGenerateRoute: (settings) {
|
||||
switch (settings.name) {
|
||||
@@ -153,7 +149,7 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
|
||||
/// when built. Use this when you want to inject objects created from the
|
||||
/// [lockScreen] in to the rest of your app so you can better guarantee that some
|
||||
/// objects, services or databases are already instantiated before using them.
|
||||
void didUnlock([Object args]) {
|
||||
void didUnlock([Object? args]) {
|
||||
if (this._didUnlockForAppLaunch) {
|
||||
this._didUnlockOnAppPaused();
|
||||
} else {
|
||||
@@ -192,17 +188,17 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
|
||||
/// Manually show the [lockScreen].
|
||||
Future<void> showLockScreen() {
|
||||
this._isLocked = true;
|
||||
return _navigatorKey.currentState.pushNamed('/lock-screen');
|
||||
return _navigatorKey.currentState!.pushNamed('/lock-screen');
|
||||
}
|
||||
|
||||
void _didUnlockOnAppLaunch(Object args) {
|
||||
void _didUnlockOnAppLaunch(Object? args) {
|
||||
this._didUnlockForAppLaunch = true;
|
||||
_navigatorKey.currentState
|
||||
_navigatorKey.currentState!
|
||||
.pushReplacementNamed('/unlocked', arguments: args);
|
||||
}
|
||||
|
||||
void _didUnlockOnAppPaused() {
|
||||
this._isLocked = false;
|
||||
_navigatorKey.currentState.pop();
|
||||
_navigatorKey.currentState!.pop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user