From 95077ec6e9ecfd96fa971da45d9f23d1aa572187 Mon Sep 17 00:00:00 2001 From: TechAurelian Date: Tue, 29 Oct 2024 20:42:34 +0200 Subject: [PATCH] Refactor UI strings and urls --- lib/common/app_strings.dart | 55 -------------------------------- lib/common/strings.dart | 49 ++++++++++++++++++++++++++++ lib/common/urls.dart | 16 ++++++++++ lib/main.dart | 4 +-- lib/screens/home.dart | 39 +++++++++++----------- lib/screens/settings_screen.dart | 8 ++--- lib/widgets/counters_drawer.dart | 14 ++++---- 7 files changed, 98 insertions(+), 87 deletions(-) delete mode 100644 lib/common/app_strings.dart create mode 100644 lib/common/strings.dart create mode 100644 lib/common/urls.dart diff --git a/lib/common/app_strings.dart b/lib/common/app_strings.dart deleted file mode 100644 index cc59d42..0000000 --- a/lib/common/app_strings.dart +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2020-2024 Hellogramming. All rights reserved. -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://hellogramming.com/helloworldcounters/license/. - -import '../screens/home.dart'; - -/// Application wide UI and URL string constants. -class AppStrings { - static const String appName = 'Hello World Counters'; - - // ----------------------------------------------------------------------------------------------- - // App Drawer - // ----------------------------------------------------------------------------------------------- - - static const String drawerTitle = appName; - static const String settingsItemTitle = 'Settings'; - static const String aboutItemTitle = 'About This App'; - static const String rateItemTitle = 'Rate App'; - static const String viewSourceItemTitle = 'View Source Code'; - - static const Map menuActions = { - MenuAction.reset: 'Reset counter', - MenuAction.share: 'Share...', - }; - - static const String resetConfirm = 'Reset counter to zero?'; - static const String resetConfirmReset = 'Reset'; - static const String resetConfirmCancel = 'Cancel'; - - static String shareText(String name, String value) => 'The $name is $value'; - - static const String rateAppURL = 'https://appliberated.com/helloworldcounters/rate/'; - - static const String aboutURL = 'https://appliberated.com/helloworldcounters/'; - - static const String viewSourceURL = 'https://github.com/Appliberated/hello_world_counters'; - - // ----------------------------------------------------------------------------------------------- - // Home Screen - Main - // ----------------------------------------------------------------------------------------------- - - static const String incrementTooltip = 'Increment'; - static const String incrementHeroTag = 'incrementHeroTag'; - static const String decrementTooltip = 'Decrement'; - static const String decrementHeroTag = 'decrementHeroTag'; - - // ----------------------------------------------------------------------------------------------- - // Settings Screen - // ----------------------------------------------------------------------------------------------- - - static const String settingsTitle = 'Settings'; - static const String counterTapModeTitle = 'Counter tap mode'; - static const String counterTapModeSubtitle = 'Tap anywhere to increase counter'; -} diff --git a/lib/common/strings.dart b/lib/common/strings.dart new file mode 100644 index 0000000..9af101c --- /dev/null +++ b/lib/common/strings.dart @@ -0,0 +1,49 @@ +// Copyright 2020-2024 Hellogramming. All rights reserved. +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://hellogramming.com/helloworldcounters/license/. + +/// App wide UI string constants. +library; + +import '../screens/home.dart'; + +const String appName = 'Hello World Counters'; + +// ----------------------------------------------------------------------------------------------- +// App Drawer +// ----------------------------------------------------------------------------------------------- + +const String drawerTitle = appName; +const String settingsItemTitle = 'Settings'; +const String aboutItemTitle = 'About This App'; +const String viewSourceItemTitle = 'View Source Code'; +const String feedbackItemTitle = 'Send Feedback'; + +const Map menuActions = { + MenuAction.reset: 'Reset counter', + MenuAction.share: 'Share...', +}; + +const String resetConfirm = 'Reset counter to zero?'; +const String resetConfirmReset = 'Reset'; +const String resetConfirmCancel = 'Cancel'; + +String shareText(String name, String value) => 'The $name is $value'; + +// ----------------------------------------------------------------------------------------------- +// Home Screen - Main +// ----------------------------------------------------------------------------------------------- + +const String incrementTooltip = 'Increment'; +const String incrementHeroTag = 'incrementHeroTag'; +const String decrementTooltip = 'Decrement'; +const String decrementHeroTag = 'decrementHeroTag'; + +// ----------------------------------------------------------------------------------------------- +// Settings Screen +// ----------------------------------------------------------------------------------------------- + +const String settingsTitle = 'Settings'; +const String counterTapModeTitle = 'Counter tap mode'; +const String counterTapModeSubtitle = 'Tap anywhere to increase counter'; diff --git a/lib/common/urls.dart b/lib/common/urls.dart new file mode 100644 index 0000000..70a0cfb --- /dev/null +++ b/lib/common/urls.dart @@ -0,0 +1,16 @@ +// Copyright 2020-2024 Hellogramming. All rights reserved. +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://hellogramming.com/helloworldcounters/license/. + +/// URLs used in the app. +library; + +/// The app's home page URL. +const String aboutURL = 'https://hellogramming.com/helloworldcounters/'; + +/// The URL to the source code repository of the app. +const String viewSourceURL = 'https://github.com/Hellogramming/hello_world_counters'; + +/// The URL for sending feedback. +const String feedbackURL = 'https://hellogramming.com/helloworldcounters/feedback/'; diff --git a/lib/main.dart b/lib/main.dart index 8d54adb..353300d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; -import 'common/app_strings.dart'; +import 'common/strings.dart' as strings; import 'screens/home.dart'; void main() { @@ -20,7 +20,7 @@ class HelloWorldCountersApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, - title: AppStrings.appName, + title: strings.appName, // A black and white theme to go with the app's colored counters theme: ThemeData.from( diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 9b6c5e4..b193eb2 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -8,7 +8,8 @@ import 'package:flutter/material.dart'; import 'package:share_plus/share_plus.dart'; import '../common/app_settings.dart'; -import '../common/app_strings.dart'; +import '../common/strings.dart' as strings; +import '../common/urls.dart' as urls; import '../models/counter.dart'; import '../utils/utils.dart'; import '../widgets/accept_cancel_dialog.dart'; @@ -61,9 +62,9 @@ class _HomeScreenState extends State { // Reset the counter after asking for confirmation. showAcceptCancelDialog( context, - AppStrings.resetConfirm, - AppStrings.resetConfirmReset, - AppStrings.resetConfirmCancel, + strings.resetConfirm, + strings.resetConfirmReset, + strings.resetConfirmCancel, () => setState(() => _counters.current.reset()), ); break; @@ -71,7 +72,7 @@ class _HomeScreenState extends State { // Share the current counter value using the platform's share sheet. final String name = _counters.current.name; final String value = toDecimalString(context, _counters.current.value); - Share.share(AppStrings.shareText(name, value), subject: name); + Share.share(strings.shareText(name, value), subject: name); break; } } @@ -83,16 +84,16 @@ class _HomeScreenState extends State { _loadSettingsScreen(); break; case DrawerExtraActions.about: - // Launch the app's about page - launchUrlExternal(context, AppStrings.aboutURL); - break; - case DrawerExtraActions.rate: - // Launch the Google Play Store page to allow the user to rate the app - launchUrlExternal(context, AppStrings.rateAppURL); + // Open the app's about page + launchUrlExternal(context, urls.aboutURL); break; case DrawerExtraActions.viewSource: - // Launch the app source code repo url - launchUrlExternal(context, AppStrings.viewSourceURL); + // Open the app source code repo url + launchUrlExternal(context, urls.viewSourceURL); + break; + case DrawerExtraActions.feedback: + // Open the app feedback page + launchUrlExternal(context, urls.feedbackURL); break; } } @@ -151,7 +152,7 @@ class _HomeScreenState extends State { (item) => PopupMenuItem( value: item, enabled: !(item == MenuAction.reset && _counters.current.value == 0), - child: Text(AppStrings.menuActions[item]!), + child: Text(strings.menuActions[item]!), ), ) .toList(); @@ -160,7 +161,7 @@ class _HomeScreenState extends State { /// Builds the main drawer that lets the user switch between color counters. Widget _buildDrawer() { return CountersDrawer( - title: AppStrings.drawerTitle, + title: strings.drawerTitle, counters: _counters, onSelected: _onDrawerSelected, onExtraSelected: _onDrawerExtraSelected, @@ -179,16 +180,16 @@ class _HomeScreenState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ FloatingActionButton.large( - heroTag: AppStrings.decrementHeroTag, + heroTag: strings.decrementHeroTag, onPressed: () => setState(() => _counters.current.decrement()), - tooltip: AppStrings.decrementTooltip, + tooltip: strings.decrementTooltip, child: const Icon(Icons.remove), ), isPortrait ? const SizedBox(height: 16.0) : const SizedBox(width: 16.0), FloatingActionButton.large( - heroTag: AppStrings.incrementHeroTag, + heroTag: strings.incrementHeroTag, onPressed: () => setState(() => _counters.current.increment()), - tooltip: AppStrings.incrementTooltip, + tooltip: strings.incrementTooltip, child: const Icon(Icons.add), ) ], diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 3d8b3fa..86809cb 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; import '../common/app_settings.dart'; -import '../common/app_strings.dart'; +import '../common/strings.dart' as strings; /// The settings screen widget that allows the user to change app settings. /// @@ -31,7 +31,7 @@ class _SettingsScreenState extends State { return Scaffold( appBar: AppBar( - title: const Text(AppStrings.settingsTitle), + title: const Text(strings.settingsTitle), ), body: Container( alignment: Alignment.topCenter, @@ -44,8 +44,8 @@ class _SettingsScreenState extends State { SwitchListTile( activeColor: Colors.black, value: widget.appSettings.counterTapMode, - title: const Text(AppStrings.counterTapModeTitle), - subtitle: const Text(AppStrings.counterTapModeSubtitle), + title: const Text(strings.counterTapModeTitle), + subtitle: const Text(strings.counterTapModeSubtitle), onChanged: (bool value) => setState(() => widget.appSettings.counterTapMode = value), ) diff --git a/lib/widgets/counters_drawer.dart b/lib/widgets/counters_drawer.dart index aa467e6..a957962 100644 --- a/lib/widgets/counters_drawer.dart +++ b/lib/widgets/counters_drawer.dart @@ -5,13 +5,13 @@ import 'package:flutter/material.dart'; -import '../common/app_strings.dart'; +import '../common/strings.dart' as strings; import '../models/counter.dart'; import '../utils/utils.dart'; import 'color_list_tile.dart'; /// Drawer extra actions enumeration. -enum DrawerExtraActions { settings, about, rate, viewSource } +enum DrawerExtraActions { settings, about, feedback, viewSource } /// A material design drawer that shows navigation links for all available counters. class CountersDrawer extends StatelessWidget { @@ -53,24 +53,24 @@ class CountersDrawer extends StatelessWidget { const Divider(), ListTile( leading: const Icon(Icons.settings), - title: const Text(AppStrings.settingsItemTitle), + title: const Text(strings.settingsItemTitle), onTap: () => _onExtraActionTap(context, DrawerExtraActions.settings), ), ListTile( leading: const Icon(Icons.help_outline), - title: const Text(AppStrings.aboutItemTitle), + title: const Text(strings.aboutItemTitle), onTap: () => _onExtraActionTap(context, DrawerExtraActions.about), ), ListTile( leading: const Icon(Icons.flutter_dash), - title: const Text(AppStrings.viewSourceItemTitle), + title: const Text(strings.viewSourceItemTitle), onTap: () => _onExtraActionTap(context, DrawerExtraActions.viewSource), ), const Divider(), ListTile( leading: const Icon(Icons.stars), - title: const Text(AppStrings.rateItemTitle), - onTap: () => _onExtraActionTap(context, DrawerExtraActions.rate), + title: const Text(strings.feedbackItemTitle), + onTap: () => _onExtraActionTap(context, DrawerExtraActions.feedback), ), ], ),