fluffychat/lib/widgets/lock_screen.dart

96 lines
3.5 KiB
Dart
Raw Permalink Normal View History

2021-05-01 11:43:54 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
2021-05-01 11:43:54 +02:00
import 'package:flutter_app_lock/flutter_app_lock.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-05-01 11:43:54 +02:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:pin_code_text_field/pin_code_text_field.dart';
import 'package:shared_preferences/shared_preferences.dart';
2021-05-01 11:43:54 +02:00
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/config/themes.dart';
2021-05-01 11:43:54 +02:00
import 'layouts/one_page_card.dart';
class LockScreen extends StatefulWidget {
2022-01-28 18:21:20 +01:00
const LockScreen({Key? key}) : super(key: key);
2021-10-14 18:09:30 +02:00
2021-05-01 11:43:54 +02:00
@override
_LockScreenState createState() => _LockScreenState();
}
class _LockScreenState extends State<LockScreen> {
final TextEditingController _textEditingController = TextEditingController();
final FocusNode _focusNode = FocusNode();
bool _wrongInput = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: FluffyThemes.light,
darkTheme: FluffyThemes.light,
localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales,
home: Builder(
builder: (context) => OnePageCard(
forceBackgroundless: true,
2021-05-01 11:43:54 +02:00
child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
elevation: 0,
centerTitle: true,
2022-01-28 18:21:20 +01:00
title: Text(L10n.of(context)!.pleaseEnterYourPin),
2021-05-01 11:43:54 +02:00
backgroundColor: Colors.transparent,
),
extendBodyBehindAppBar: true,
body: Container(
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
2021-10-14 18:09:30 +02:00
stops: const [
2021-05-01 11:43:54 +02:00
0.1,
0.4,
0.6,
0.9,
],
colors: [
Theme.of(context).secondaryHeaderColor.withAlpha(16),
Theme.of(context).primaryColor.withAlpha(16),
2021-05-24 10:59:00 +02:00
Theme.of(context).colorScheme.secondary.withAlpha(16),
2021-05-01 11:43:54 +02:00
Theme.of(context).backgroundColor.withAlpha(16),
],
),
),
alignment: Alignment.center,
child: PinCodeTextField(
autofocus: true,
controller: _textEditingController,
focusNode: _focusNode,
pinBoxRadius: AppConfig.borderRadius,
2021-10-14 18:09:30 +02:00
pinTextStyle: const TextStyle(fontSize: 32),
2021-05-01 11:43:54 +02:00
hideCharacter: true,
hasError: _wrongInput,
onDone: (String input) async {
if (input ==
await ([TargetPlatform.linux]
.contains(Theme.of(context).platform)
? SharedPreferences.getInstance().then((prefs) =>
prefs.getString(SettingKeys.appLockKey))
: const FlutterSecureStorage()
.read(key: SettingKeys.appLockKey))) {
2022-01-28 18:21:20 +01:00
AppLock.of(context)!.didUnlock();
2021-05-01 11:43:54 +02:00
} else {
_textEditingController.clear();
setState(() => _wrongInput = true);
_focusNode.requestFocus();
}
},
),
),
),
),
),
);
}
}