From 07142e25a7483ed4d948845b525ad6984ce5d936 Mon Sep 17 00:00:00 2001 From: Yoshi Date: Fri, 30 Aug 2024 22:31:42 +0300 Subject: [PATCH] Hide map --- lib/app/data/weather.dart | 1 + lib/app/data/weather.g.dart | 179 +++++++++++++------- lib/app/modules/home.dart | 42 +++-- lib/app/modules/settings/view/settings.dart | 143 +++++++++++----- pubspec.lock | 12 +- pubspec.yaml | 3 +- 6 files changed, 263 insertions(+), 117 deletions(-) diff --git a/lib/app/data/weather.dart b/lib/app/data/weather.dart index 09d475a..c5e45db 100644 --- a/lib/app/data/weather.dart +++ b/lib/app/data/weather.dart @@ -13,6 +13,7 @@ class Settings { bool amoledTheme = false; bool roundDegree = false; bool largeElement = false; + bool hideMap = false; String? widgetBackgroundColor; String? widgetTextColor; String measurements = 'metric'; diff --git a/lib/app/data/weather.g.dart b/lib/app/data/weather.g.dart index 0b516b4..5b6ffca 100644 --- a/lib/app/data/weather.g.dart +++ b/lib/app/data/weather.g.dart @@ -27,88 +27,93 @@ const SettingsSchema = CollectionSchema( name: r'degrees', type: IsarType.string, ), - r'language': PropertySchema( + r'hideMap': PropertySchema( id: 2, + name: r'hideMap', + type: IsarType.bool, + ), + r'language': PropertySchema( + id: 3, name: r'language', type: IsarType.string, ), r'largeElement': PropertySchema( - id: 3, + id: 4, name: r'largeElement', type: IsarType.bool, ), r'location': PropertySchema( - id: 4, + id: 5, name: r'location', type: IsarType.bool, ), r'materialColor': PropertySchema( - id: 5, + id: 6, name: r'materialColor', type: IsarType.bool, ), r'measurements': PropertySchema( - id: 6, + id: 7, name: r'measurements', type: IsarType.string, ), r'notifications': PropertySchema( - id: 7, + id: 8, name: r'notifications', type: IsarType.bool, ), r'onboard': PropertySchema( - id: 8, + id: 9, name: r'onboard', type: IsarType.bool, ), r'pressure': PropertySchema( - id: 9, + id: 10, name: r'pressure', type: IsarType.string, ), r'roundDegree': PropertySchema( - id: 10, + id: 11, name: r'roundDegree', type: IsarType.bool, ), r'theme': PropertySchema( - id: 11, + id: 12, name: r'theme', type: IsarType.string, ), r'timeEnd': PropertySchema( - id: 12, + id: 13, name: r'timeEnd', type: IsarType.string, ), r'timeRange': PropertySchema( - id: 13, + id: 14, name: r'timeRange', type: IsarType.long, ), r'timeStart': PropertySchema( - id: 14, + id: 15, name: r'timeStart', type: IsarType.string, ), r'timeformat': PropertySchema( - id: 15, + id: 16, name: r'timeformat', type: IsarType.string, ), r'widgetBackgroundColor': PropertySchema( - id: 16, + id: 17, name: r'widgetBackgroundColor', type: IsarType.string, ), r'widgetTextColor': PropertySchema( - id: 17, + id: 18, name: r'widgetTextColor', type: IsarType.string, ), r'wind': PropertySchema( - id: 18, + id: 19, name: r'wind', type: IsarType.string, ) @@ -185,23 +190,24 @@ void _settingsSerialize( ) { writer.writeBool(offsets[0], object.amoledTheme); writer.writeString(offsets[1], object.degrees); - writer.writeString(offsets[2], object.language); - writer.writeBool(offsets[3], object.largeElement); - writer.writeBool(offsets[4], object.location); - writer.writeBool(offsets[5], object.materialColor); - writer.writeString(offsets[6], object.measurements); - writer.writeBool(offsets[7], object.notifications); - writer.writeBool(offsets[8], object.onboard); - writer.writeString(offsets[9], object.pressure); - writer.writeBool(offsets[10], object.roundDegree); - writer.writeString(offsets[11], object.theme); - writer.writeString(offsets[12], object.timeEnd); - writer.writeLong(offsets[13], object.timeRange); - writer.writeString(offsets[14], object.timeStart); - writer.writeString(offsets[15], object.timeformat); - writer.writeString(offsets[16], object.widgetBackgroundColor); - writer.writeString(offsets[17], object.widgetTextColor); - writer.writeString(offsets[18], object.wind); + writer.writeBool(offsets[2], object.hideMap); + writer.writeString(offsets[3], object.language); + writer.writeBool(offsets[4], object.largeElement); + writer.writeBool(offsets[5], object.location); + writer.writeBool(offsets[6], object.materialColor); + writer.writeString(offsets[7], object.measurements); + writer.writeBool(offsets[8], object.notifications); + writer.writeBool(offsets[9], object.onboard); + writer.writeString(offsets[10], object.pressure); + writer.writeBool(offsets[11], object.roundDegree); + writer.writeString(offsets[12], object.theme); + writer.writeString(offsets[13], object.timeEnd); + writer.writeLong(offsets[14], object.timeRange); + writer.writeString(offsets[15], object.timeStart); + writer.writeString(offsets[16], object.timeformat); + writer.writeString(offsets[17], object.widgetBackgroundColor); + writer.writeString(offsets[18], object.widgetTextColor); + writer.writeString(offsets[19], object.wind); } Settings _settingsDeserialize( @@ -213,24 +219,25 @@ Settings _settingsDeserialize( final object = Settings(); object.amoledTheme = reader.readBool(offsets[0]); object.degrees = reader.readString(offsets[1]); + object.hideMap = reader.readBool(offsets[2]); object.id = id; - object.language = reader.readStringOrNull(offsets[2]); - object.largeElement = reader.readBool(offsets[3]); - object.location = reader.readBool(offsets[4]); - object.materialColor = reader.readBool(offsets[5]); - object.measurements = reader.readString(offsets[6]); - object.notifications = reader.readBool(offsets[7]); - object.onboard = reader.readBool(offsets[8]); - object.pressure = reader.readString(offsets[9]); - object.roundDegree = reader.readBool(offsets[10]); - object.theme = reader.readStringOrNull(offsets[11]); - object.timeEnd = reader.readStringOrNull(offsets[12]); - object.timeRange = reader.readLongOrNull(offsets[13]); - object.timeStart = reader.readStringOrNull(offsets[14]); - object.timeformat = reader.readString(offsets[15]); - object.widgetBackgroundColor = reader.readStringOrNull(offsets[16]); - object.widgetTextColor = reader.readStringOrNull(offsets[17]); - object.wind = reader.readString(offsets[18]); + object.language = reader.readStringOrNull(offsets[3]); + object.largeElement = reader.readBool(offsets[4]); + object.location = reader.readBool(offsets[5]); + object.materialColor = reader.readBool(offsets[6]); + object.measurements = reader.readString(offsets[7]); + object.notifications = reader.readBool(offsets[8]); + object.onboard = reader.readBool(offsets[9]); + object.pressure = reader.readString(offsets[10]); + object.roundDegree = reader.readBool(offsets[11]); + object.theme = reader.readStringOrNull(offsets[12]); + object.timeEnd = reader.readStringOrNull(offsets[13]); + object.timeRange = reader.readLongOrNull(offsets[14]); + object.timeStart = reader.readStringOrNull(offsets[15]); + object.timeformat = reader.readString(offsets[16]); + object.widgetBackgroundColor = reader.readStringOrNull(offsets[17]); + object.widgetTextColor = reader.readStringOrNull(offsets[18]); + object.wind = reader.readString(offsets[19]); return object; } @@ -246,38 +253,40 @@ P _settingsDeserializeProp

( case 1: return (reader.readString(offset)) as P; case 2: - return (reader.readStringOrNull(offset)) as P; - case 3: return (reader.readBool(offset)) as P; + case 3: + return (reader.readStringOrNull(offset)) as P; case 4: return (reader.readBool(offset)) as P; case 5: return (reader.readBool(offset)) as P; case 6: - return (reader.readString(offset)) as P; - case 7: return (reader.readBool(offset)) as P; + case 7: + return (reader.readString(offset)) as P; case 8: return (reader.readBool(offset)) as P; case 9: - return (reader.readString(offset)) as P; - case 10: return (reader.readBool(offset)) as P; + case 10: + return (reader.readString(offset)) as P; case 11: - return (reader.readStringOrNull(offset)) as P; + return (reader.readBool(offset)) as P; case 12: return (reader.readStringOrNull(offset)) as P; case 13: - return (reader.readLongOrNull(offset)) as P; - case 14: return (reader.readStringOrNull(offset)) as P; + case 14: + return (reader.readLongOrNull(offset)) as P; case 15: - return (reader.readString(offset)) as P; - case 16: return (reader.readStringOrNull(offset)) as P; + case 16: + return (reader.readString(offset)) as P; case 17: return (reader.readStringOrNull(offset)) as P; case 18: + return (reader.readStringOrNull(offset)) as P; + case 19: return (reader.readString(offset)) as P; default: throw IsarError('Unknown property with id $propertyId'); @@ -513,6 +522,16 @@ extension SettingsQueryFilter }); } + QueryBuilder hideMapEqualTo( + bool value) { + return QueryBuilder.apply(this, (query) { + return query.addFilterCondition(FilterCondition.equalTo( + property: r'hideMap', + value: value, + )); + }); + } + QueryBuilder idEqualTo(Id value) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.equalTo( @@ -2145,6 +2164,18 @@ extension SettingsQuerySortBy on QueryBuilder { }); } + QueryBuilder sortByHideMap() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'hideMap', Sort.asc); + }); + } + + QueryBuilder sortByHideMapDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'hideMap', Sort.desc); + }); + } + QueryBuilder sortByLanguage() { return QueryBuilder.apply(this, (query) { return query.addSortBy(r'language', Sort.asc); @@ -2377,6 +2408,18 @@ extension SettingsQuerySortThenBy }); } + QueryBuilder thenByHideMap() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'hideMap', Sort.asc); + }); + } + + QueryBuilder thenByHideMapDesc() { + return QueryBuilder.apply(this, (query) { + return query.addSortBy(r'hideMap', Sort.desc); + }); + } + QueryBuilder thenById() { return QueryBuilder.apply(this, (query) { return query.addSortBy(r'id', Sort.asc); @@ -2610,6 +2653,12 @@ extension SettingsQueryWhereDistinct }); } + QueryBuilder distinctByHideMap() { + return QueryBuilder.apply(this, (query) { + return query.addDistinctBy(r'hideMap'); + }); + } + QueryBuilder distinctByLanguage( {bool caseSensitive = true}) { return QueryBuilder.apply(this, (query) { @@ -2745,6 +2794,12 @@ extension SettingsQueryProperty }); } + QueryBuilder hideMapProperty() { + return QueryBuilder.apply(this, (query) { + return query.addPropertyName(r'hideMap'); + }); + } + QueryBuilder languageProperty() { return QueryBuilder.apply(this, (query) { return query.addPropertyName(r'language'); diff --git a/lib/app/modules/home.dart b/lib/app/modules/home.dart index 2d97edc..a25b028 100644 --- a/lib/app/modules/home.dart +++ b/lib/app/modules/home.dart @@ -30,31 +30,43 @@ class _HomePageState extends State with TickerProviderStateMixin { final weatherController = Get.put(WeatherController()); final _controller = TextEditingController(); - final pages = [ + final List pages = [ const WeatherPage(), const ListWeatherCard(), - const MapWeather(), + if (!settings.hideMap) const MapWeather(), const SettingsPage(), ]; @override void initState() { + super.initState(); getData(); + setupTabController(); + } + + @override + void dispose() { + tabController.dispose(); + super.dispose(); + } + + void setupTabController() { tabController = TabController( initialIndex: tabIndex, length: pages.length, vsync: this, ); + tabController.animation?.addListener(() { int value = (tabController.animation!.value).round(); if (value != tabIndex) setState(() => tabIndex = value); }); + tabController.addListener(() { setState(() { tabIndex = tabController.index; }); }); - super.initState(); } void getData() async { @@ -199,10 +211,15 @@ class _HomePageState extends State with TickerProviderStateMixin { 'cities'.tr, style: textStyle, ), - 2 => Text( - 'map'.tr, - style: textStyle, - ), + 2 => settings.hideMap + ? Text( + 'settings_full'.tr, + style: textStyle, + ) + : Text( + 'map'.tr, + style: textStyle, + ), 3 => Text( 'settings_full'.tr, style: textStyle, @@ -253,11 +270,12 @@ class _HomePageState extends State with TickerProviderStateMixin { selectedIcon: const Icon(IconsaxPlusBold.buildings), label: 'cities'.tr, ), - NavigationDestination( - icon: const Icon(IconsaxPlusLinear.map), - selectedIcon: const Icon(IconsaxPlusBold.map), - label: 'map'.tr, - ), + if (!settings.hideMap) + NavigationDestination( + icon: const Icon(IconsaxPlusLinear.map), + selectedIcon: const Icon(IconsaxPlusBold.map), + label: 'map'.tr, + ), NavigationDestination( icon: const Icon(IconsaxPlusLinear.category), selectedIcon: const Icon(IconsaxPlusBold.category), diff --git a/lib/app/modules/settings/view/settings.dart b/lib/app/modules/settings/view/settings.dart index 29ae59f..9fe8ab8 100644 --- a/lib/app/modules/settings/view/settings.dart +++ b/lib/app/modules/settings/view/settings.dart @@ -18,6 +18,7 @@ import 'package:rain/app/modules/settings/widgets/setting_card.dart'; import 'package:rain/main.dart'; import 'package:rain/theme/theme_controller.dart'; import 'package:rain/utils/color_converter.dart'; +import 'package:restart_app/restart_app.dart'; class SettingsPage extends StatefulWidget { const SettingsPage({super.key}); @@ -844,47 +845,109 @@ class _SettingsPageState extends State { }, ), SettingCard( - icon: const Icon(IconsaxPlusLinear.trash_square), - text: 'clearCacheStore'.tr, - onPressed: () => showAdaptiveDialog( - context: context, - builder: (context) => AlertDialog.adaptive( - title: Text( - 'deletedCacheStore'.tr, - style: context.textTheme.titleLarge, - ), - content: Text( - 'deletedCacheStoreQuery'.tr, - style: context.textTheme.titleMedium, - ), - actions: [ - TextButton( - onPressed: () => Get.back(), - child: Text( - 'cancel'.tr, - style: context.textTheme.titleMedium?.copyWith( - color: Colors.blueAccent, - ), - ), - ), - TextButton( - onPressed: () async { - final dir = await getTemporaryDirectory(); - final cacheStoreFuture = FileCacheStore( - '${dir.path}${Platform.pathSeparator}MapTiles'); - cacheStoreFuture.clean(); - Get.back(); - }, - child: Text( - 'delete'.tr, - style: context.textTheme.titleMedium?.copyWith( - color: Colors.red, - ), + icon: const Icon(IconsaxPlusLinear.map), + text: 'map'.tr, + onPressed: () { + showModalBottomSheet( + context: context, + builder: (BuildContext context) { + return Padding( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).padding.bottom), + child: StatefulBuilder( + builder: (BuildContext context, setState) { + return SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: + const EdgeInsets.symmetric(vertical: 15), + child: Text( + 'map'.tr, + style: context.textTheme.titleLarge?.copyWith( + fontSize: 20, + ), + ), + ), + SettingCard( + elevation: 4, + icon: const Icon( + IconsaxPlusLinear.location_slash), + text: 'hideMap'.tr, + switcher: true, + value: settings.hideMap, + onChange: (value) { + settings.hideMap = value; + isar.writeTxnSync( + () => isar.settings.putSync(settings), + ); + setState(() {}); + Future.delayed( + const Duration(milliseconds: 500), + () => Restart.restartApp(), + ); + }, + ), + SettingCard( + elevation: 4, + icon: + const Icon(IconsaxPlusLinear.trash_square), + text: 'clearCacheStore'.tr, + onPressed: () => showAdaptiveDialog( + context: context, + builder: (context) => AlertDialog.adaptive( + title: Text( + 'deletedCacheStore'.tr, + style: context.textTheme.titleLarge, + ), + content: Text( + 'deletedCacheStoreQuery'.tr, + style: context.textTheme.titleMedium, + ), + actions: [ + TextButton( + onPressed: () => Get.back(), + child: Text( + 'cancel'.tr, + style: context.textTheme.titleMedium + ?.copyWith( + color: Colors.blueAccent, + ), + ), + ), + TextButton( + onPressed: () async { + final dir = + await getTemporaryDirectory(); + final cacheStoreFuture = FileCacheStore( + '${dir.path}${Platform.pathSeparator}MapTiles'); + cacheStoreFuture.clean(); + Get.back(); + }, + child: Text( + 'delete'.tr, + style: context.textTheme.titleMedium + ?.copyWith( + color: Colors.red, + ), + ), + ), + ], + ), + ), + ), + const Gap(10), + ], + ), + ); + }, ), - ), - ], - ), - ), + ); + }, + ); + }, ), SettingCard( icon: const Icon(IconsaxPlusLinear.language_square), diff --git a/pubspec.lock b/pubspec.lock index 21468d6..393acfa 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -449,10 +449,10 @@ packages: dependency: "direct main" description: name: flutter_timezone - sha256: "06150cc6dde7a0309acc3f1c38380819ae774be4d942934c824c4fa64efadffa" + sha256: ea53c61c9152f271a5e30624a624184804947b6a733ff2b64186bb2579446892 url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.1" flutter_web_plugins: dependency: transitive description: flutter @@ -1010,6 +1010,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + restart_app: + dependency: "direct main" + description: + name: restart_app + sha256: b37daeb1c02fcab30e19d9e30b6fdd215bd53577efd927042eb77cf6f09daadb + url: "https://pub.dev" + source: hosted + version: "1.2.1" scrollable_positioned_list: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 1b553b2..04fbe2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: geolocator: ^13.0.1 home_widget: ^0.7.0 workmanager: ^0.5.2 + restart_app: ^1.2.1 flutter_map: ^7.0.2 google_fonts: ^6.2.1 url_launcher: ^6.3.0 @@ -33,7 +34,7 @@ dependencies: path_provider: ^2.1.4 # quick_settings: ^1.0.1 json_annotation: ^4.9.0 - flutter_timezone: ^3.0.0 + flutter_timezone: ^3.0.1 device_info_plus: ^10.1.2 package_info_plus: ^8.0.2 connectivity_plus: ^6.0.5