Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Make custom key pad for pin a separate widget and reuse it instead of writing duplicates of it

ashilkn365e8e6eb8cc
diff --git a/mobile/lib/ui/settings/lock_screen/custom_pin_keypad.dart b/mobile/lib/ui/settings/lock_screen/custom_pin_keypad.dart
new file mode 100644
index 0000000000..d388a2f906
--- /dev/null
+++ b/mobile/lib/ui/settings/lock_screen/custom_pin_keypad.dart
@@ -0,0 +1,196 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+
+class CustomPinKeypad extends StatelessWidget {
+ final TextEditingController controller;
+ const CustomPinKeypad({required this.controller, super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return SafeArea(
+ child: Container(
+ padding: const EdgeInsets.all(2),
+ color: getEnteColorScheme(context).strokeFainter,
+ child: Column(
+ children: [
+ Row(
+ children: [
+ _Button(
+ text: '',
+ number: '1',
+ onTap: () {
+ _onKeyTap('1');
+ },
+ ),
+ _Button(
+ text: "ABC",
+ number: '2',
+ onTap: () {
+ _onKeyTap('2');
+ },
+ ),
+ _Button(
+ text: "DEF",
+ number: '3',
+ onTap: () {
+ _onKeyTap('3');
+ },
+ ),
+ ],
+ ),
+ Row(
+ children: [
+ _Button(
+ number: '4',
+ text: "GHI",
+ onTap: () {
+ _onKeyTap('4');
+ },
+ ),
+ _Button(
+ number: '5',
+ text: 'JKL',
+ onTap: () {
+ _onKeyTap('5');
+ },
+ ),
+ _Button(
+ number: '6',
+ text: 'MNO',
+ onTap: () {
+ _onKeyTap('6');
+ },
+ ),
+ ],
+ ),
+ Row(
+ children: [
+ _Button(
+ number: '7',
+ text: 'PQRS',
+ onTap: () {
+ _onKeyTap('7');
+ },
+ ),
+ _Button(
+ number: '8',
+ text: 'TUV',
+ onTap: () {
+ _onKeyTap('8');
+ },
+ ),
+ _Button(
+ number: '9',
+ text: 'WXYZ',
+ onTap: () {
+ _onKeyTap('9');
+ },
+ ),
+ ],
+ ),
+ Row(
+ children: [
+ const _Button(
+ number: '',
+ text: '',
+ muteButton: true,
+ onTap: null,
+ ),
+ _Button(
+ number: '0',
+ text: '',
+ onTap: () {
+ _onKeyTap('0');
+ },
+ ),
+ _Button(
+ number: '',
+ text: '',
+ icon: const Icon(Icons.backspace_outlined),
+ onTap: () {
+ _onBackspace();
+ },
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ void _onKeyTap(String number) {
+ controller.text += number;
+ return;
+ }
+
+ void _onBackspace() {
+ if (controller.text.isNotEmpty) {
+ controller.text =
+ controller.text.substring(0, controller.text.length - 1);
+ }
+ return;
+ }
+}
+
+class _Button extends StatelessWidget {
+ final String number;
+ final String text;
+ final VoidCallback? onTap;
+ final bool muteButton;
+ final Widget? icon;
+ const _Button({
+ required this.number,
+ required this.text,
+ this.muteButton = false,
+ required this.onTap,
+ this.icon,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ return Expanded(
+ child: GestureDetector(
+ onTap: onTap,
+ child: Container(
+ margin: const EdgeInsets.all(4),
+ decoration: BoxDecoration(
+ shape: BoxShape.rectangle,
+ borderRadius: BorderRadius.circular(6),
+ color: muteButton
+ ? colorScheme.fillFaintPressed
+ : icon == null
+ ? colorScheme.backgroundElevated2
+ : null,
+ ),
+ child: Center(
+ child: muteButton
+ ? const SizedBox.shrink()
+ : icon != null
+ ? Container(
+ child: icon,
+ )
+ : Container(
+ padding: const EdgeInsets.all(4),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(
+ number,
+ style: textTheme.h3,
+ ),
+ Text(
+ text,
+ style: textTheme.tinyBold,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_confirm_pin.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_confirm_pin.dart
index c10a33323c..a970416750 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_confirm_pin.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_confirm_pin.dart
@@ -1,9 +1,8 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
-import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/theme/text_style.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
+import "package:photos/ui/settings/lock_screen/custom_pin_keypad.dart";
import "package:photos/utils/lock_screen_settings.dart";
import "package:pinput/pinput.dart";
@@ -191,197 +190,9 @@ class _LockScreenConfirmPinState extends State<LockScreenConfirmPin> {
isPortrait
? const Spacer()
: const Padding(padding: EdgeInsets.all(12)),
- customKeyPad(colorTheme, textTheme),
+ CustomPinKeypad(controller: _confirmPinController),
],
),
);
}
-
- Widget customKeyPad(EnteColorScheme colorTheme, EnteTextTheme textTheme) {
- return SafeArea(
- child: Container(
- padding: const EdgeInsets.all(2),
- color: colorTheme.strokeFainter,
- child: Column(
- children: [
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: '',
- number: '1',
- onTap: () {
- _onKeyTap('1');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: "ABC",
- number: '2',
- onTap: () {
- _onKeyTap('2');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: "DEF",
- number: '3',
- onTap: () {
- _onKeyTap('3');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '4',
- text: "GHI",
- onTap: () {
- _onKeyTap('4');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '5',
- text: 'JKL',
- onTap: () {
- _onKeyTap('5');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '6',
- text: 'MNO',
- onTap: () {
- _onKeyTap('6');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '7',
- text: 'PQRS',
- onTap: () {
- _onKeyTap('7');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '8',
- text: 'TUV',
- onTap: () {
- _onKeyTap('8');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '9',
- text: 'WXYZ',
- onTap: () {
- _onKeyTap('9');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '',
- text: '',
- muteButton: true,
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '0',
- text: '',
- onTap: () {
- _onKeyTap('0');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '',
- text: '',
- icons: const Icon(Icons.backspace_outlined),
- onTap: () {
- _onBackspace();
- },
- ),
- ],
- ),
- ],
- ),
- ),
- );
- }
-
- Widget buttonWidget({
- colorTheme,
- textTheme,
- text,
- number,
- muteButton = false,
- icons,
- onTap,
- }) {
- return Expanded(
- child: GestureDetector(
- onTap: onTap,
- child: Container(
- margin: const EdgeInsets.all(4),
- decoration: BoxDecoration(
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.circular(6),
- color: muteButton
- ? colorTheme.fillFaintPressed
- : icons == null
- ? colorTheme.backgroundElevated2
- : null,
- ),
- child: Center(
- child: muteButton
- ? Container()
- : icons != null
- ? Container(
- child: icons,
- )
- : Container(
- padding: const EdgeInsets.all(4),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- number,
- style: textTheme.h3,
- ),
- Text(
- text,
- style: textTheme.small,
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
}
diff --git a/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart b/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
index d1328bc8b3..6b36b9b623 100644
--- a/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
+++ b/mobile/lib/ui/settings/lock_screen/lock_screen_pin.dart
@@ -7,6 +7,7 @@ import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/theme/text_style.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
+import "package:photos/ui/settings/lock_screen/custom_pin_keypad.dart";
import "package:photos/ui/settings/lock_screen/lock_screen_confirm_pin.dart";
import "package:photos/ui/settings/lock_screen/lock_screen_options.dart";
import "package:photos/utils/crypto_util.dart";
@@ -262,197 +263,9 @@ class _LockScreenPinState extends State<LockScreenPin> {
isPortrait
? const Spacer()
: const Padding(padding: EdgeInsets.all(12)),
- customKeyPad(colorTheme, textTheme),
+ CustomPinKeypad(controller: _pinController),
],
),
);
}
-
- Widget customKeyPad(EnteColorScheme colorTheme, EnteTextTheme textTheme) {
- return SafeArea(
- child: Container(
- padding: const EdgeInsets.all(2),
- color: colorTheme.strokeFainter,
- child: Column(
- children: [
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: '',
- number: '1',
- onTap: () {
- _onKeyTap('1');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: "ABC",
- number: '2',
- onTap: () {
- _onKeyTap('2');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- text: "DEF",
- number: '3',
- onTap: () {
- _onKeyTap('3');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '4',
- text: "GHI",
- onTap: () {
- _onKeyTap('4');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '5',
- text: 'JKL',
- onTap: () {
- _onKeyTap('5');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '6',
- text: 'MNO',
- onTap: () {
- _onKeyTap('6');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '7',
- text: 'PQRS',
- onTap: () {
- _onKeyTap('7');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '8',
- text: 'TUV',
- onTap: () {
- _onKeyTap('8');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '9',
- text: 'WXYZ',
- onTap: () {
- _onKeyTap('9');
- },
- ),
- ],
- ),
- Row(
- children: [
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '',
- text: '',
- muteButton: true,
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '0',
- text: '',
- onTap: () {
- _onKeyTap('0');
- },
- ),
- buttonWidget(
- colorTheme: colorTheme,
- textTheme: textTheme,
- number: '',
- text: '',
- icons: const Icon(Icons.backspace_outlined),
- onTap: () {
- _onBackspace();
- },
- ),
- ],
- ),
- ],
- ),
- ),
- );
- }
-
- Widget buttonWidget({
- colorTheme,
- textTheme,
- text,
- number,
- muteButton = false,
- icons,
- onTap,
- }) {
- return Expanded(
- child: GestureDetector(
- onTap: onTap,
- child: Container(
- margin: const EdgeInsets.all(4),
- decoration: BoxDecoration(
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.circular(6),
- color: muteButton
- ? colorTheme.fillFaintPressed
- : icons == null
- ? colorTheme.backgroundElevated2
- : null,
- ),
- child: Center(
- child: muteButton
- ? Container()
- : icons != null
- ? Container(
- child: icons,
- )
- : Container(
- padding: const EdgeInsets.all(4),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- number,
- style: textTheme.h3,
- ),
- Text(
- text,
- style: textTheme.miniBold,
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
}