Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Extract reusable const widget subtrees

ashil-pilot969068dcb43f
diff --git a/mobile/apps/photos/lib/ui/account/email_entry_page.dart b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
index 2303e3f8fd..0c69caf9a3 100644
--- a/mobile/apps/photos/lib/ui/account/email_entry_page.dart
+++ b/mobile/apps/photos/lib/ui/account/email_entry_page.dart
@@ -116,7 +116,7 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
onTap: _isFormValid() ? _submitCreateAccount : null,
),
),
- bottomNavigationBar: isKeyboardOpen ? null : _getLoginPrompt(),
+ bottomNavigationBar: isKeyboardOpen ? null : const _LoginPrompt(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
@@ -341,33 +341,6 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
}
}
- Widget _getLoginPrompt() {
- final colors = context.componentColors;
- return SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.only(bottom: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- context.strings.alreadyHaveAnAccount,
- style: TextStyles.body.copyWith(color: colors.textLight),
- ),
- const SizedBox(width: 4),
- ButtonComponent(
- label: context.strings.logInLabel,
- variant: ButtonComponentVariant.link,
- size: ButtonComponentSize.small,
- shouldSurfaceExecutionStates: false,
- onTap: _goToLoginPage,
- ),
- ],
- ),
- ),
- );
- }
-
void _onEmailChanged(String value) {
_emailValidationTimer?.cancel();
@@ -475,11 +448,41 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
_hasAgreedToTOS &&
_passwordIsValid;
}
+}
- Future<void> _goToLoginPage() async {
- FocusScope.of(context).unfocus();
- await Navigator.of(
- context,
- ).push(MaterialPageRoute(builder: (_) => const LoginPage()));
+class _LoginPrompt extends StatelessWidget {
+ const _LoginPrompt();
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ return SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(
+ context.strings.alreadyHaveAnAccount,
+ style: TextStyles.body.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(width: 4),
+ ButtonComponent(
+ label: context.strings.logInLabel,
+ variant: ButtonComponentVariant.link,
+ size: ButtonComponentSize.small,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ FocusScope.of(context).unfocus();
+ await Navigator.of(
+ context,
+ ).push(MaterialPageRoute(builder: (_) => const LoginPage()));
+ },
+ ),
+ ],
+ ),
+ ),
+ );
}
}
diff --git a/mobile/apps/photos/lib/ui/account/login_page.dart b/mobile/apps/photos/lib/ui/account/login_page.dart
index 4d59e464d9..44ab11949f 100644
--- a/mobile/apps/photos/lib/ui/account/login_page.dart
+++ b/mobile/apps/photos/lib/ui/account/login_page.dart
@@ -91,7 +91,7 @@ class _LoginPageState extends State<LoginPage> {
onTap: _emailIsValid ? _submitLoginEmail : null,
),
),
- bottomNavigationBar: isKeyboardOpen ? null : _getSignUpPrompt(),
+ bottomNavigationBar: isKeyboardOpen ? null : const _SignUpPrompt(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
@@ -132,34 +132,6 @@ class _LoginPageState extends State<LoginPage> {
);
}
- Widget _getSignUpPrompt() {
- final colors = context.componentColors;
- return SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.only(bottom: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- context.strings.dontHaveAnAccount,
- style: TextStyles.body.copyWith(color: colors.textLight),
- ),
- const SizedBox(width: 4),
-
- ButtonComponent(
- label: context.strings.signUp,
- variant: ButtonComponentVariant.link,
- size: ButtonComponentSize.small,
- shouldSurfaceExecutionStates: false,
- onTap: _goToSignUpPage,
- ),
- ],
- ),
- ),
- );
- }
-
void _onEmailChanged(String value) {
_validationTimer?.cancel();
@@ -233,11 +205,41 @@ class _LoginPageState extends State<LoginPage> {
if (!mounted) return;
FocusScope.of(context).unfocus();
}
+}
- Future<void> _goToSignUpPage() async {
- FocusScope.of(context).unfocus();
- await Navigator.of(
- context,
- ).push(MaterialPageRoute(builder: (_) => const EmailEntryPage()));
+class _SignUpPrompt extends StatelessWidget {
+ const _SignUpPrompt();
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ return SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: 8),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(
+ context.strings.dontHaveAnAccount,
+ style: TextStyles.body.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(width: 4),
+ ButtonComponent(
+ label: context.strings.signUp,
+ variant: ButtonComponentVariant.link,
+ size: ButtonComponentSize.small,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ FocusScope.of(context).unfocus();
+ await Navigator.of(context).push(
+ MaterialPageRoute(builder: (_) => const EmailEntryPage()),
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ );
}
}
diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart b/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart
index 9ee4f1ee47..32c8ccf3a6 100644
--- a/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart
@@ -102,9 +102,11 @@ class _MemoryShareSelectionSheetState
height: sheetHeight,
child: GalleryBoundariesProvider(
child: BottomSheetComponent(
+ // Rebuild the reporter so sheet layout changes refresh the boundary.
+ // ignore: prefer_const_constructors
header: _MemoryShareSheetBoundary(
position: BoundaryPosition.top,
- child: _buildHeader(context, l10n),
+ child: const _MemoryShareSheetHeader(),
),
showCloseButton: false,
padding: const EdgeInsets.symmetric(vertical: Spacing.xl),
@@ -127,40 +129,6 @@ class _MemoryShareSelectionSheetState
);
}
- Widget _buildHeader(BuildContext context, StringsLocalizations l10n) {
- final colors = context.componentColors;
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),
- child: SizedBox(
- height: 38,
- child: Row(
- children: [
- Expanded(
- child: Text(
- l10n.shareMemory,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.h1Bold.copyWith(color: colors.textBase),
- ),
- ),
- const SizedBox(width: Spacing.md),
- IconButtonComponent(
- key: const ValueKey("memory-share-close"),
- tooltip: l10n.close,
- variant: IconButtonComponentVariant.circular,
- shouldSurfaceExecutionStates: false,
- icon: const HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- size: IconSizes.small,
- ),
- onTap: () => Navigator.of(context).pop(),
- ),
- ],
- ),
- ),
- );
- }
-
Widget _buildSelectionControls(StringsLocalizations l10n) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -278,6 +246,46 @@ class _MemoryShareSelectionSheetState
// Source: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=18629-312441&m=dev
const double _figmaSheetHeightRatio = 634 / 812;
+class _MemoryShareSheetHeader extends StatelessWidget {
+ const _MemoryShareSheetHeader();
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.strings;
+ final colors = context.componentColors;
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),
+ child: SizedBox(
+ height: 38,
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(
+ l10n.shareMemory,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.h1Bold.copyWith(color: colors.textBase),
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ IconButtonComponent(
+ key: const ValueKey("memory-share-close"),
+ tooltip: l10n.close,
+ variant: IconButtonComponentVariant.circular,
+ shouldSurfaceExecutionStates: false,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ ),
+ onTap: () => Navigator.of(context).pop(),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
class _MemoryShareSheetBoundary extends StatefulWidget {
final BoundaryPosition position;
final Widget child;
diff --git a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
index 1e4504254a..442fae1732 100644
--- a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
@@ -148,8 +148,8 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
: const SizedBox.shrink(),
if (_showErrorBanner) HeaderErrorWidget(error: _syncError),
if (_shouldShowLargeBackupBanner) _largeBackupBanner(context),
- if (_showMlBanner && !_showErrorBanner) _mlBanner(context),
- if (_showVerificationBanner()) _recoveryKeyBanner(context),
+ if (_showMlBanner && !_showErrorBanner) const _MachineLearningBanner(),
+ if (_showVerificationBanner()) const _RecoveryKeyBanner(),
],
);
}
@@ -175,7 +175,22 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
);
}
- Widget _mlBanner(BuildContext context) {
+ bool _showVerificationBanner() {
+ if (_showErrorBanner ||
+ _showErrorBanner ||
+ flagService.recoveryKeyVerified) {
+ return false;
+ }
+ final DateTime installTime = localSettings.getInstallDateTime();
+ return DateTime.now().difference(installTime).inDays >= 3;
+ }
+}
+
+class _MachineLearningBanner extends StatelessWidget {
+ const _MachineLearningBanner();
+
+ @override
+ Widget build(BuildContext context) {
final l10n = context.strings;
return _bannerPadding(
BannerComponent(
@@ -194,8 +209,13 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
),
);
}
+}
+
+class _RecoveryKeyBanner extends StatelessWidget {
+ const _RecoveryKeyBanner();
- Widget _recoveryKeyBanner(BuildContext context) {
+ @override
+ Widget build(BuildContext context) {
return _bannerPadding(
BannerComponent(
leadingIcon: HugeIcons.strokeRoundedAlertCircle,
@@ -212,23 +232,13 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
),
);
}
+}
- Widget _bannerPadding(Widget child) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
- child: child,
- );
- }
-
- bool _showVerificationBanner() {
- if (_showErrorBanner ||
- _showErrorBanner ||
- flagService.recoveryKeyVerified) {
- return false;
- }
- final DateTime installTime = localSettings.getInstallDateTime();
- return DateTime.now().difference(installTime).inDays >= 3;
- }
+Widget _bannerPadding(Widget child) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
+ child: child,
+ );
}
class SyncStatusWidget extends StatefulWidget {
diff --git a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
index 83f6b9c944..cda81b0eb0 100644
--- a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart
@@ -145,7 +145,7 @@ class _MachineLearningSettingsPageState
return SettingsPageScaffold(
title: context.strings.mlConsent,
children: [
- _buildDisabledMLDescription(context),
+ const _MLConsentDescription(),
const SizedBox(height: 20),
Center(
child: Image.asset(
@@ -241,34 +241,6 @@ class _MachineLearningSettingsPageState
}
}
- Widget _buildDisabledMLDescription(BuildContext context) {
- final colors = context.componentColors;
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- context.strings.mlConsentDescription,
- textAlign: TextAlign.left,
- style: TextStyles.mini.copyWith(color: colors.textLight),
- ),
- const SizedBox(height: 6),
- GestureDetector(
- onTap: () async => _openMLPrivacyPolicy(context),
- child: Text(
- context.strings.mlConsentPrivacy,
- textAlign: TextAlign.left,
- style: TextStyles.mini.copyWith(
- color: colors.textLight,
- decoration: TextDecoration.underline,
- decorationColor: colors.textLight,
- ),
- ),
- ),
- ],
- );
- }
-
Widget _buildDisabledConsentAckRow(BuildContext context) {
final colors = context.componentColors;
@@ -302,19 +274,6 @@ class _MachineLearningSettingsPageState
);
}
- Future<void> _openMLPrivacyPolicy(BuildContext context) async {
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage(
- context.strings.privacyPolicyTitle,
- "https://ente.com/privacy",
- );
- },
- ),
- );
- }
-
Widget _getMlSettings(BuildContext context) {
final hasEnabled = hasGrantedMLConsent;
if (!hasEnabled) {
@@ -381,6 +340,52 @@ class _MachineLearningSettingsPageState
}
}
+class _MLConsentDescription extends StatelessWidget {
+ const _MLConsentDescription();
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.mlConsentDescription,
+ textAlign: TextAlign.left,
+ style: TextStyles.mini.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(height: 6),
+ GestureDetector(
+ onTap: () async => _openMLPrivacyPolicy(context),
+ child: Text(
+ context.strings.mlConsentPrivacy,
+ textAlign: TextAlign.left,
+ style: TextStyles.mini.copyWith(
+ color: colors.textLight,
+ decoration: TextDecoration.underline,
+ decorationColor: colors.textLight,
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Future<void> _openMLPrivacyPolicy(BuildContext context) async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return WebPage(
+ context.strings.privacyPolicyTitle,
+ "https://ente.com/privacy",
+ );
+ },
+ ),
+ );
+ }
+}
+
class ModelLoadingState extends StatefulWidget {
const ModelLoadingState({super.key});
diff --git a/mobile/apps/photos/lib/ui/viewer/file/ocr/text_detector_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/ocr/text_detector_widget.dart
index 11c9e75414..6c43963224 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/ocr/text_detector_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/ocr/text_detector_widget.dart
@@ -333,11 +333,11 @@ class _TextDetectorWidgetState extends State<TextDetectorWidget> {
_detectedTextBlocks != null &&
_detectedTextBlocks!.isEmpty &&
_errorMessage == null)
- Positioned(
+ const Positioned(
top: 100,
left: 0,
right: 0,
- child: Center(child: _buildNoTextMessage()),
+ child: Center(child: _NoTextMessage()),
),
],
),
@@ -432,33 +432,6 @@ class _TextDetectorWidgetState extends State<TextDetectorWidget> {
);
}
- Widget _buildNoTextMessage() {
- return Container(
- padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
- decoration: BoxDecoration(
- color: Colors.black.withValues(alpha: 0.5),
- borderRadius: BorderRadius.circular(20),
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(
- Icons.search_off,
- color: textBaseDark.withValues(alpha: 0.7),
- size: 16,
- ),
- const SizedBox(width: 8),
- Text(
- context.strings.ocrNoTextDetected,
- style: getEnteTextTheme(
- context,
- ).small.copyWith(color: textBaseDark.withValues(alpha: 0.8)),
- ),
- ],
- ),
- );
- }
-
bool get _hasActiveSelection => _textOverlayController.hasActiveSelection;
bool _selectTextAtPosition(Offset globalPosition) {
@@ -495,3 +468,35 @@ class _TextDetectorWidgetState extends State<TextDetectorWidget> {
widget.controller._notifyStateChanged();
}
}
+
+class _NoTextMessage extends StatelessWidget {
+ const _NoTextMessage();
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
+ decoration: BoxDecoration(
+ color: Colors.black.withValues(alpha: 0.5),
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ Icons.search_off,
+ color: textBaseDark.withValues(alpha: 0.7),
+ size: 16,
+ ),
+ const SizedBox(width: 8),
+ Text(
+ context.strings.ocrNoTextDetected,
+ style: getEnteTextTheme(
+ context,
+ ).small.copyWith(color: textBaseDark.withValues(alpha: 0.8)),
+ ),
+ ],
+ ),
+ );
+ }
+}