From dd353e8e73ac4d2e416a4908d6233f8b76698f7b Mon Sep 17 00:00:00 2001 From: TechAurelian Date: Sat, 28 Sep 2024 16:55:59 +0300 Subject: [PATCH] Refactor import statements for common files --- lib/common/{app_const.dart => consts.dart} | 1 + .../{app_settings.dart => preferences.dart} | 0 lib/common/{ui_strings.dart => strings.dart} | 6 +++-- lib/common/{app_theme.dart => theme.dart} | 0 lib/common/{app_urls.dart => urls.dart} | 0 lib/main.dart | 8 +++---- lib/screens/available_colors_screen.dart | 4 ++-- lib/screens/color_favorites_screen.dart | 22 +++++++++---------- lib/screens/color_info_screen.dart | 6 ++--- lib/screens/random_color_screen.dart | 15 +++++++------ lib/utils/utils.dart | 2 +- lib/widgets/color_info_list.dart | 2 +- lib/widgets/color_list_view.dart | 2 +- lib/widgets/internal/app_drawer.dart | 13 ++++++----- 14 files changed, 43 insertions(+), 38 deletions(-) rename lib/common/{app_const.dart => consts.dart} (93%) rename lib/common/{app_settings.dart => preferences.dart} (100%) rename lib/common/{ui_strings.dart => strings.dart} (99%) rename lib/common/{app_theme.dart => theme.dart} (100%) rename lib/common/{app_urls.dart => urls.dart} (100%) diff --git a/lib/common/app_const.dart b/lib/common/consts.dart similarity index 93% rename from lib/common/app_const.dart rename to lib/common/consts.dart index 8378472..89a00ad 100644 --- a/lib/common/app_const.dart +++ b/lib/common/consts.dart @@ -12,4 +12,5 @@ const String noNameColorParam = 'noname'; /// The color swatch image file name for a given hex code. String colorSwatchFileName(String hexCode) => 'colorhap_${hexCode}_random_color_swatch.png'; +/// The height of the color list item. const double colorListItemExtent = 128.0; diff --git a/lib/common/app_settings.dart b/lib/common/preferences.dart similarity index 100% rename from lib/common/app_settings.dart rename to lib/common/preferences.dart diff --git a/lib/common/ui_strings.dart b/lib/common/strings.dart similarity index 99% rename from lib/common/ui_strings.dart rename to lib/common/strings.dart index 748b27a..c341619 100644 --- a/lib/common/ui_strings.dart +++ b/lib/common/strings.dart @@ -3,6 +3,9 @@ // license that can be found in the LICENSE file or at // https://www.tecdrop.com/colorhap/license/. +/// User interface strings for the ColorHap app. +library; + import '../models/color_type.dart'; // ----------------------------------------------------------------------------------------------- @@ -36,8 +39,6 @@ const Map colorTypePlural = { ColorType.trueColor: 'True Colors', }; -String availableColors(ColorType value) => 'Available ${colorTypePlural[value]}'; - // ----------------------------------------------------------------------------------------------- // Drawer items // ----------------------------------------------------------------------------------------------- @@ -123,3 +124,4 @@ const String favoritesExported = 'Favorites exported to clipboard in CSV format' // Available Colors Screen // ----------------------------------------------------------------------------------------------- +String availableColors(ColorType value) => 'Available ${colorTypePlural[value]}'; diff --git a/lib/common/app_theme.dart b/lib/common/theme.dart similarity index 100% rename from lib/common/app_theme.dart rename to lib/common/theme.dart diff --git a/lib/common/app_urls.dart b/lib/common/urls.dart similarity index 100% rename from lib/common/app_urls.dart rename to lib/common/urls.dart diff --git a/lib/main.dart b/lib/main.dart index e527730..b385127 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; -import 'common/app_settings.dart' as settings; -import 'common/app_theme.dart'; -import 'common/ui_strings.dart' as strings; +import 'common/preferences.dart' as preferences; +import 'common/strings.dart' as strings; +import 'common/theme.dart'; import 'screens/random_color_screen.dart'; Future main() async { @@ -20,7 +20,7 @@ Future main() async { // First try to load the app settings from Shared Preferences await Future.any([ - settings.loadSettings(), + preferences.loadSettings(), Future.delayed(const Duration(seconds: 5)), ]); diff --git a/lib/screens/available_colors_screen.dart b/lib/screens/available_colors_screen.dart index acb6268..d9e3016 100644 --- a/lib/screens/available_colors_screen.dart +++ b/lib/screens/available_colors_screen.dart @@ -6,8 +6,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import '../common/app_const.dart' as consts; -import '../common/ui_strings.dart' as strings; +import '../common/consts.dart' as consts; +import '../common/strings.dart' as strings; import '../models/color_type.dart'; import '../models/more.dart'; import '../models/random_color_generator.dart'; diff --git a/lib/screens/color_favorites_screen.dart b/lib/screens/color_favorites_screen.dart index f2aef22..edc8c43 100644 --- a/lib/screens/color_favorites_screen.dart +++ b/lib/screens/color_favorites_screen.dart @@ -5,8 +5,8 @@ import 'package:flutter/material.dart'; -import '../common/app_settings.dart' as settings; -import '../common/ui_strings.dart' as strings; +import '../common/preferences.dart' as preferences; +import '../common/strings.dart' as strings; import '../models/random_color.dart'; import '../utils/utils.dart' as utils; import '../widgets/color_list_view.dart'; @@ -33,7 +33,7 @@ class _ColorFavoritesScreenState extends State { // Exports the favorite colors as a CSV file case _AppBarActions.exportFavoritesAsCsv: ScaffoldMessengerState messengerState = ScaffoldMessenger.of(context); - await utils.copyToClipboard(context, settings.colorFavoritesList.toCsvString()); + await utils.copyToClipboard(context, preferences.colorFavoritesList.toCsvString()); utils.showSnackBarForAsync(messengerState, strings.favoritesExported); break; // Clears all the favorite colors @@ -45,7 +45,7 @@ class _ColorFavoritesScreenState extends State { positiveActionText: strings.clearFavoritesDialogPositiveAction, ); if (showConfirmation == true) { - setState(() => settings.colorFavoritesList.clear()); + setState(() => preferences.colorFavoritesList.clear()); } break; } @@ -57,14 +57,14 @@ class _ColorFavoritesScreenState extends State { void _deleteFavoriteColor(int index) { // First remove the color from the list late final RandomColor randomColor; - setState(() => randomColor = settings.colorFavoritesList.removeAt(index)); + setState(() => randomColor = preferences.colorFavoritesList.removeAt(index)); // Then display a snackbar with an undo action final snackBar = SnackBar( content: const Text(strings.removedFromFavorites), action: SnackBarAction( label: strings.undoRemoveFromFavorites, - onPressed: () => setState(() => settings.colorFavoritesList.insert(index, randomColor)), + onPressed: () => setState(() => preferences.colorFavoritesList.insert(index, randomColor)), ), ); ScaffoldMessenger.of(context) @@ -82,10 +82,10 @@ class _ColorFavoritesScreenState extends State { child: Scaffold( appBar: _AppBar( title: const Text(strings.favoriteColorsScreenTitle), - haveFavorites: settings.colorFavoritesList.length > 0, + haveFavorites: preferences.colorFavoritesList.length > 0, onAction: _onAppBarAction, ), - body: settings.colorFavoritesList.length > 0 + body: preferences.colorFavoritesList.length > 0 ? _buildFavoritesListView() : _buildNoFavoritesMessage(), ), @@ -93,7 +93,7 @@ class _ColorFavoritesScreenState extends State { } ColorListItemData _getItemData(int index) { - final RandomColor randomColor = settings.colorFavoritesList.elementAt(index); + final RandomColor randomColor = preferences.colorFavoritesList.elementAt(index); return ( color: randomColor.color, title: randomColor.longTitle, @@ -105,11 +105,11 @@ class _ColorFavoritesScreenState extends State { Widget _buildFavoritesListView() { return ColorListView( key: const PageStorageKey('favoritesListView'), - itemCount: () => settings.colorFavoritesList.length, + itemCount: () => preferences.colorFavoritesList.length, itemData: _getItemData, itemButton: (_) => (icon: Icons.delete, tooltip: strings.removeFavTooltip), onItemTap: (int index) => Navigator.of(context).pop( - settings.colorFavoritesList.elementAt(index), + preferences.colorFavoritesList.elementAt(index), ), onItemButtonPressed: _deleteFavoriteColor, ); diff --git a/lib/screens/color_info_screen.dart b/lib/screens/color_info_screen.dart index 696a4c0..aedf7e2 100644 --- a/lib/screens/color_info_screen.dart +++ b/lib/screens/color_info_screen.dart @@ -8,9 +8,9 @@ import 'package:flutter/services.dart'; import 'package:share_plus/share_plus.dart'; -import '../common/app_const.dart' as consts; -import '../common/app_urls.dart' as urls; -import '../common/ui_strings.dart' as strings; +import '../common/consts.dart' as consts; +import '../common/strings.dart' as strings; +import '../common/urls.dart' as urls; import '../models/random_color.dart'; import '../utils/color_utils.dart' as color_utils; import '../utils/utils.dart' as utils; diff --git a/lib/screens/random_color_screen.dart b/lib/screens/random_color_screen.dart index 4e047b9..adea830 100644 --- a/lib/screens/random_color_screen.dart +++ b/lib/screens/random_color_screen.dart @@ -5,8 +5,8 @@ import 'package:flutter/material.dart'; -import '../common/app_settings.dart' as settings; -import '../common/ui_strings.dart' as strings; +import '../common/preferences.dart' as preferences; +import '../common/strings.dart' as strings; import '../models/color_type.dart'; import '../models/random_color_generator.dart'; import '../models/random_color.dart'; @@ -50,7 +50,7 @@ class _RandomColorScreenState extends State { super.initState(); // Restore the last selected color type - _colorType = settings.colorType; + _colorType = preferences.colorType; // Generate the first random color _shuffleColor(); @@ -59,7 +59,7 @@ class _RandomColorScreenState extends State { void _updateState(RandomColor? randomColor) { setState(() { if (randomColor != null) _randomColor = randomColor; - _colorFavIndex = settings.colorFavoritesList.indexOf(_randomColor); + _colorFavIndex = preferences.colorFavoritesList.indexOf(_randomColor); }); } @@ -95,8 +95,9 @@ class _RandomColorScreenState extends State { // Toggle the current color in the favorites list case _AppBarActions.toggleFav: setState(() { - _colorFavIndex = settings.colorFavoritesList.toggle(_randomColor, index: _colorFavIndex); - settings.saveColorFavoritesList(); + _colorFavIndex = + preferences.colorFavoritesList.toggle(_randomColor, index: _colorFavIndex); + preferences.saveColorFavoritesList(); }); break; @@ -143,7 +144,7 @@ class _RandomColorScreenState extends State { randomColor: _randomColor, colorType: _colorType, onColorTypeChange: (ColorType colorType) { - settings.colorType = _colorType = colorType; + preferences.colorType = _colorType = colorType; _shuffleColor(); }, onColorFavoritesTap: _gotoColorFavoritesScreen, diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 5a1b7b9..ad5f2c4 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -12,7 +12,7 @@ import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../common/ui_strings.dart' as strings; +import '../common/strings.dart' as strings; final NumberFormat _numberFormat = NumberFormat.decimalPattern(); diff --git a/lib/widgets/color_info_list.dart b/lib/widgets/color_info_list.dart index 9e5af4a..602f412 100644 --- a/lib/widgets/color_info_list.dart +++ b/lib/widgets/color_info_list.dart @@ -6,7 +6,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import '../common/ui_strings.dart' as strings; +import '../common/strings.dart' as strings; import '../models/random_color.dart'; import '../utils/color_utils.dart' as color_utils; diff --git a/lib/widgets/color_list_view.dart b/lib/widgets/color_list_view.dart index 03e6188..a090c8a 100644 --- a/lib/widgets/color_list_view.dart +++ b/lib/widgets/color_list_view.dart @@ -7,7 +7,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import '../common/app_const.dart' as consts; +import '../common/consts.dart' as consts; import '../utils/color_utils.dart' as color_utils; typedef ColorListItemData = ({ diff --git a/lib/widgets/internal/app_drawer.dart b/lib/widgets/internal/app_drawer.dart index 5e4ec1d..0e3332a 100644 --- a/lib/widgets/internal/app_drawer.dart +++ b/lib/widgets/internal/app_drawer.dart @@ -5,10 +5,10 @@ import 'package:flutter/material.dart'; -import '../../common/app_settings.dart' as settings; -import '../../common/app_urls.dart' as urls; import '../../common/custom_icons.dart' as custom_icons; -import '../../common/ui_strings.dart' as strings; +import '../../common/preferences.dart' as preferences; +import '../../common/strings.dart' as strings; +import '../../common/urls.dart' as urls; import '../../models/color_type.dart'; import '../../models/random_color_generator.dart'; import '../../models/random_color.dart'; @@ -238,11 +238,12 @@ class AppDrawer extends StatelessWidget { // Color Favorites drawer item _buildItem( context, - icon: settings.colorFavoritesList.length > 0 ? Icons.favorite : Icons.favorite_border, + icon: + preferences.colorFavoritesList.length > 0 ? Icons.favorite : Icons.favorite_border, title: strings.colorFavoritesDrawer, subtitle: strings.colorFavoritesSubtitle( - utils.intToCommaSeparatedString(settings.colorFavoritesList.length), - isPlural: settings.colorFavoritesList.length != 1, + utils.intToCommaSeparatedString(preferences.colorFavoritesList.length), + isPlural: preferences.colorFavoritesList.length != 1, ), item: AppDrawerItems.colorFavorites, ),