Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor lock screen components to use ente_components and simplify UI structure

aman-pilotdcf8d2dfe9ba
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_auto_lock.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_auto_lock.dart
index 421c0959d6..3ab76680b0 100644
--- a/mobile/packages/lock_screen/lib/ui/lock_screen_auto_lock.dart
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_auto_lock.dart
@@ -1,12 +1,6 @@
+import 'package:ente_components/ente_components.dart';
import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_strings/ente_strings.dart';
-import 'package:ente_ui/components/captioned_text_widget.dart';
-import 'package:ente_ui/components/divider_widget.dart';
-import 'package:ente_ui/components/menu_item_widget.dart';
-import 'package:ente_ui/components/separators.dart';
-import 'package:ente_ui/components/title_bar_title_widget.dart';
-import 'package:ente_ui/components/title_bar_widget.dart';
-import 'package:ente_ui/theme/ente_theme.dart';
import 'package:flutter/material.dart';
class LockScreenAutoLock extends StatefulWidget {
@@ -20,31 +14,15 @@ class _LockScreenAutoLockState extends State<LockScreenAutoLock> {
@override
Widget build(BuildContext context) {
return Scaffold(
- body: CustomScrollView(
- primary: false,
- slivers: <Widget>[
- TitleBarWidget(
- flexibleSpaceTitle: TitleBarTitleWidget(
- title: context.strings.autoLock,
- ),
- ),
+ backgroundColor: context.componentColors.backgroundBase,
+ body: AppBarComponent(
+ title: context.strings.autoLock,
+ slivers: [
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 20),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Column(
- children: [
- ClipRRect(
- borderRadius: BorderRadius.all(Radius.circular(8)),
- child: AutoLockItems(),
- ),
- ],
- ),
- ],
- ),
+ child: AutoLockItems(),
);
}, childCount: 1),
),
@@ -63,7 +41,6 @@ class AutoLockItems extends StatefulWidget {
class _AutoLockItemsState extends State<AutoLockItems> {
final autoLockDurations = LockScreenSettings.instance.autoLockDurations;
- List<Widget> items = [];
Duration currentAutoLockTime = const Duration(seconds: 5);
@override
@@ -80,43 +57,29 @@ class _AutoLockItemsState extends State<AutoLockItems> {
@override
Widget build(BuildContext context) {
- items.clear();
- for (Duration autoLockDuration in autoLockDurations) {
- items.add(_menuItemForPicker(autoLockDuration));
- }
- items = addSeparators(
- items,
- DividerWidget(
- dividerType: DividerType.menuNoIcon,
- bgColor: getEnteColorScheme(context).fillFaint,
- ),
- );
- return Column(mainAxisSize: MainAxisSize.min, children: items);
- }
-
- Widget _menuItemForPicker(Duration autoLockTime) {
- return MenuItemWidget(
- key: ValueKey(autoLockTime),
- menuItemColor: getEnteColorScheme(context).fillFaint,
- captionedTextWidget: CaptionedTextWidget(
- title: _formatTime(autoLockTime),
- ),
- trailingIcon: currentAutoLockTime == autoLockTime ? Icons.check : null,
- alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: true,
- isBottomBorderRadiusRemoved: true,
- showOnlyLoadingState: true,
- onTap: () async {
- await LockScreenSettings.instance
- .setAutoLockTime(autoLockTime)
- .then(
- (value) => {
- setState(() {
- currentAutoLockTime = autoLockTime;
- }),
- },
- );
- },
+ final colors = context.componentColors;
+ return MenuGroupComponent(
+ showDividers: true,
+ items: [
+ for (final autoLockDuration in autoLockDurations)
+ MenuComponent(
+ key: ValueKey(autoLockDuration),
+ title: _formatTime(autoLockDuration),
+ trailing: currentAutoLockTime == autoLockDuration
+ ? Icon(Icons.check, color: colors.textBase)
+ : null,
+ showOnlyLoadingState: true,
+ onTap: () async {
+ await LockScreenSettings.instance
+ .setAutoLockTime(autoLockDuration)
+ .then(
+ (value) => setState(() {
+ currentAutoLockTime = autoLockDuration;
+ }),
+ );
+ },
+ ),
+ ],
);
}
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_confirm_pin.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_confirm_pin.dart
index d0c3565864..bf018ba9ca 100644
--- a/mobile/packages/lock_screen/lib/ui/lock_screen_confirm_pin.dart
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_confirm_pin.dart
@@ -1,15 +1,13 @@
import "dart:io";
+import "package:ente_components/ente_components.dart";
import "package:ente_lock_screen/lock_screen_settings.dart";
import "package:ente_lock_screen/ui/custom_pin_keypad.dart";
+import "package:ente_lock_screen/ui/lock_screen_pin_input.dart";
import "package:ente_strings/ente_strings.dart";
-import "package:ente_ui/theme/colors.dart";
-import "package:ente_ui/theme/ente_theme.dart";
-import "package:ente_ui/theme/text_style.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_svg/flutter_svg.dart";
-import "package:pinput/pinput.dart";
class LockScreenConfirmPin extends StatefulWidget {
const LockScreenConfirmPin({super.key, required this.pin});
@@ -58,8 +56,7 @@ class _LockScreenConfirmPinState extends State<LockScreenConfirmPin> {
@override
Widget build(BuildContext context) {
- final colorTheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
+ final colorTheme = context.componentColors;
return Scaffold(
backgroundColor: colorTheme.backgroundBase,
@@ -77,89 +74,22 @@ class _LockScreenConfirmPinState extends State<LockScreenConfirmPin> {
title: SvgPicture.asset(
LockScreenSettings.instance.appLogoAsset,
height: LockScreenSettings.instance.appLogoHeight,
- colorFilter: ColorFilter.mode(colorTheme.primary700, BlendMode.srcIn),
+ colorFilter: ColorFilter.mode(colorTheme.primary, BlendMode.srcIn),
),
),
floatingActionButton: isPlatformDesktop
? null
: CustomPinKeypad(controller: _confirmPinController),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
- body: SingleChildScrollView(child: _getBody(colorTheme, textTheme)),
- );
- }
-
- Widget _getBody(EnteColorScheme colorTheme, EnteTextTheme textTheme) {
- final pinPutDecoration = PinTheme(
- height: 48,
- width: 48,
- padding: const EdgeInsets.only(top: 6.0),
- decoration: BoxDecoration(
- color: colorTheme.backgroundBase,
- border: Border.all(color: colorTheme.fillMuted, width: 1),
- borderRadius: BorderRadius.circular(15.0),
- ),
- );
-
- return Center(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 24.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- const SizedBox(height: 40),
- Image.asset('assets/lock_screen_icon.png', width: 129, height: 95),
- const SizedBox(height: 24),
- Text(context.strings.reEnterPin, style: textTheme.bodyBold),
- const Padding(padding: EdgeInsets.all(12)),
- Pinput(
- length: 4,
- showCursor: false,
- useNativeKeyboard: isPlatformDesktop,
- autofocus: true,
- controller: _confirmPinController,
- defaultPinTheme: pinPutDecoration.copyWith(
- textStyle: textTheme.h3Bold,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillMuted),
- ),
- ),
- submittedPinTheme: pinPutDecoration.copyWith(
- textStyle: textTheme.h3Bold.copyWith(
- color: colorTheme.primary700,
- ),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.primary700),
- ),
- ),
- followingPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillMuted),
- ),
- ),
- focusedPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillBase),
- ),
- ),
- errorPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.warning400),
- ),
- ),
- errorText: '',
- obscureText: true,
- obscuringCharacter: '*',
- forceErrorState: isConfirmPinValid,
- onCompleted: (value) async {
- await _confirmPinMatch();
- },
- ),
- ],
+ body: SingleChildScrollView(
+ child: LockScreenPinInput(
+ title: context.strings.reEnterPin,
+ controller: _confirmPinController,
+ useNativeKeyboard: isPlatformDesktop,
+ forceErrorState: isConfirmPinValid,
+ onCompleted: (_) async {
+ await _confirmPinMatch();
+ },
),
),
);
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
index d08c4d7435..50493e3eb6 100644
--- a/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
@@ -1,17 +1,15 @@
import "dart:io";
+import "package:ente_components/ente_components.dart";
import "package:ente_lock_screen/lock_screen_settings.dart";
import "package:ente_lock_screen/ui/custom_pin_keypad.dart";
import "package:ente_lock_screen/ui/lock_screen_confirm_pin.dart";
import "package:ente_lock_screen/ui/lock_screen_options.dart";
+import "package:ente_lock_screen/ui/lock_screen_pin_input.dart";
import "package:ente_strings/ente_strings.dart";
-import "package:ente_ui/theme/colors.dart";
-import "package:ente_ui/theme/ente_theme.dart";
-import "package:ente_ui/theme/text_style.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_svg/flutter_svg.dart";
-import 'package:pinput/pinput.dart';
/// [isChangingLockScreenSettings] Authentication required for changing lock screen settings.
/// Set to true when the app requires the user to authenticate before allowing
@@ -124,19 +122,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
@override
Widget build(BuildContext context) {
- final colorTheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
-
- final pinPutDecoration = PinTheme(
- height: 48,
- width: 48,
- padding: const EdgeInsets.only(top: 6.0),
- decoration: BoxDecoration(
- color: colorTheme.backgroundBase,
- border: Border.all(color: colorTheme.fillMuted, width: 1),
- borderRadius: BorderRadius.circular(15.0),
- ),
- );
+ final colorTheme = context.componentColors;
return Scaffold(
backgroundColor: colorTheme.backgroundBase,
appBar: AppBar(
@@ -153,7 +139,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
title: SvgPicture.asset(
LockScreenSettings.instance.appLogoAsset,
height: LockScreenSettings.instance.appLogoHeight,
- colorFilter: ColorFilter.mode(colorTheme.primary700, BlendMode.srcIn),
+ colorFilter: ColorFilter.mode(colorTheme.primary, BlendMode.srcIn),
),
),
floatingActionButton: isPlatformDesktop
@@ -161,81 +147,16 @@ class _LockScreenPinState extends State<LockScreenPin> {
: CustomPinKeypad(controller: _pinController),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body: SingleChildScrollView(
- child: _getBody(colorTheme, textTheme, pinPutDecoration),
- ),
- );
- }
-
- Widget _getBody(
- EnteColorScheme colorTheme,
- EnteTextTheme textTheme,
- PinTheme pinPutDecoration,
- ) {
- return Center(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 24.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- const SizedBox(height: 40),
- Image.asset('assets/lock_screen_icon.png', width: 129, height: 95),
- const SizedBox(height: 24),
- Text(
- widget.isChangingLockScreenSettings
- ? context.strings.enterAppLockPin
- : context.strings.setNewPin,
- style: textTheme.bodyBold,
- ),
- const Padding(padding: EdgeInsets.all(12)),
- Pinput(
- length: 4,
- showCursor: false,
- useNativeKeyboard: isPlatformDesktop,
- controller: _pinController,
- autofocus: true,
- defaultPinTheme: pinPutDecoration.copyWith(
- textStyle: textTheme.h3Bold,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillMuted),
- ),
- ),
- submittedPinTheme: pinPutDecoration.copyWith(
- textStyle: textTheme.h3Bold.copyWith(
- color: colorTheme.primary700,
- ),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.primary700),
- ),
- ),
- followingPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillMuted),
- ),
- ),
- focusedPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.fillBase),
- ),
- ),
- errorPinTheme: pinPutDecoration.copyWith(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(15.0),
- border: Border.all(color: colorTheme.warning400),
- ),
- ),
- forceErrorState: isPinValid,
- obscureText: true,
- obscuringCharacter: '*',
- errorText: '',
- onCompleted: (value) async {
- await _confirmPin(_pinController.text);
- },
- ),
- ],
+ child: LockScreenPinInput(
+ title: widget.isChangingLockScreenSettings
+ ? context.strings.enterAppLockPin
+ : context.strings.setNewPin,
+ controller: _pinController,
+ useNativeKeyboard: isPlatformDesktop,
+ forceErrorState: isPinValid,
+ onCompleted: (_) async {
+ await _confirmPin(_pinController.text);
+ },
),
),
);
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_pin_input.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_pin_input.dart
new file mode 100644
index 0000000000..26fc0db18f
--- /dev/null
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_pin_input.dart
@@ -0,0 +1,95 @@
+import "package:ente_components/ente_components.dart";
+import "package:flutter/material.dart";
+import "package:pinput/pinput.dart";
+
+class LockScreenPinInput extends StatelessWidget {
+ const LockScreenPinInput({
+ super.key,
+ required this.title,
+ required this.controller,
+ required this.useNativeKeyboard,
+ required this.forceErrorState,
+ required this.onCompleted,
+ });
+
+ final String title;
+ final TextEditingController controller;
+ final bool useNativeKeyboard;
+ final bool forceErrorState;
+ final ValueChanged<String> onCompleted;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorTheme = context.componentColors;
+ final pinPutDecoration = PinTheme(
+ height: 48,
+ width: 48,
+ padding: const EdgeInsets.only(top: 6.0),
+ decoration: BoxDecoration(
+ color: colorTheme.backgroundBase,
+ border: Border.all(color: colorTheme.strokeDark, width: 1),
+ borderRadius: BorderRadius.circular(15.0),
+ ),
+ );
+
+ return Center(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 24.0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ const SizedBox(height: 40),
+ Image.asset('assets/lock_screen_icon.png', width: 129, height: 95),
+ const SizedBox(height: 24),
+ Text(title, style: TextStyles.bodyBold),
+ const Padding(padding: EdgeInsets.all(12)),
+ Pinput(
+ length: 4,
+ showCursor: false,
+ useNativeKeyboard: useNativeKeyboard,
+ controller: controller,
+ autofocus: true,
+ defaultPinTheme: pinPutDecoration.copyWith(
+ textStyle: TextStyles.h2,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(15.0),
+ border: Border.all(color: colorTheme.strokeDark),
+ ),
+ ),
+ submittedPinTheme: pinPutDecoration.copyWith(
+ textStyle: TextStyles.h2.copyWith(color: colorTheme.primary),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(15.0),
+ border: Border.all(color: colorTheme.primary),
+ ),
+ ),
+ followingPinTheme: pinPutDecoration.copyWith(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(15.0),
+ border: Border.all(color: colorTheme.strokeDark),
+ ),
+ ),
+ focusedPinTheme: pinPutDecoration.copyWith(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(15.0),
+ border: Border.all(color: colorTheme.fillBase),
+ ),
+ ),
+ errorPinTheme: pinPutDecoration.copyWith(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(15.0),
+ border: Border.all(color: colorTheme.warning),
+ ),
+ ),
+ forceErrorState: forceErrorState,
+ obscureText: true,
+ obscuringCharacter: '*',
+ errorText: '',
+ onCompleted: onCompleted,
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}