This commit is contained in:
Yoshi 2024-08-30 22:31:42 +03:00
parent 55e813749a
commit 07142e25a7
6 changed files with 263 additions and 117 deletions

View file

@ -13,6 +13,7 @@ class Settings {
bool amoledTheme = false; bool amoledTheme = false;
bool roundDegree = false; bool roundDegree = false;
bool largeElement = false; bool largeElement = false;
bool hideMap = false;
String? widgetBackgroundColor; String? widgetBackgroundColor;
String? widgetTextColor; String? widgetTextColor;
String measurements = 'metric'; String measurements = 'metric';

View file

@ -27,88 +27,93 @@ const SettingsSchema = CollectionSchema(
name: r'degrees', name: r'degrees',
type: IsarType.string, type: IsarType.string,
), ),
r'language': PropertySchema( r'hideMap': PropertySchema(
id: 2, id: 2,
name: r'hideMap',
type: IsarType.bool,
),
r'language': PropertySchema(
id: 3,
name: r'language', name: r'language',
type: IsarType.string, type: IsarType.string,
), ),
r'largeElement': PropertySchema( r'largeElement': PropertySchema(
id: 3, id: 4,
name: r'largeElement', name: r'largeElement',
type: IsarType.bool, type: IsarType.bool,
), ),
r'location': PropertySchema( r'location': PropertySchema(
id: 4, id: 5,
name: r'location', name: r'location',
type: IsarType.bool, type: IsarType.bool,
), ),
r'materialColor': PropertySchema( r'materialColor': PropertySchema(
id: 5, id: 6,
name: r'materialColor', name: r'materialColor',
type: IsarType.bool, type: IsarType.bool,
), ),
r'measurements': PropertySchema( r'measurements': PropertySchema(
id: 6, id: 7,
name: r'measurements', name: r'measurements',
type: IsarType.string, type: IsarType.string,
), ),
r'notifications': PropertySchema( r'notifications': PropertySchema(
id: 7, id: 8,
name: r'notifications', name: r'notifications',
type: IsarType.bool, type: IsarType.bool,
), ),
r'onboard': PropertySchema( r'onboard': PropertySchema(
id: 8, id: 9,
name: r'onboard', name: r'onboard',
type: IsarType.bool, type: IsarType.bool,
), ),
r'pressure': PropertySchema( r'pressure': PropertySchema(
id: 9, id: 10,
name: r'pressure', name: r'pressure',
type: IsarType.string, type: IsarType.string,
), ),
r'roundDegree': PropertySchema( r'roundDegree': PropertySchema(
id: 10, id: 11,
name: r'roundDegree', name: r'roundDegree',
type: IsarType.bool, type: IsarType.bool,
), ),
r'theme': PropertySchema( r'theme': PropertySchema(
id: 11, id: 12,
name: r'theme', name: r'theme',
type: IsarType.string, type: IsarType.string,
), ),
r'timeEnd': PropertySchema( r'timeEnd': PropertySchema(
id: 12, id: 13,
name: r'timeEnd', name: r'timeEnd',
type: IsarType.string, type: IsarType.string,
), ),
r'timeRange': PropertySchema( r'timeRange': PropertySchema(
id: 13, id: 14,
name: r'timeRange', name: r'timeRange',
type: IsarType.long, type: IsarType.long,
), ),
r'timeStart': PropertySchema( r'timeStart': PropertySchema(
id: 14, id: 15,
name: r'timeStart', name: r'timeStart',
type: IsarType.string, type: IsarType.string,
), ),
r'timeformat': PropertySchema( r'timeformat': PropertySchema(
id: 15, id: 16,
name: r'timeformat', name: r'timeformat',
type: IsarType.string, type: IsarType.string,
), ),
r'widgetBackgroundColor': PropertySchema( r'widgetBackgroundColor': PropertySchema(
id: 16, id: 17,
name: r'widgetBackgroundColor', name: r'widgetBackgroundColor',
type: IsarType.string, type: IsarType.string,
), ),
r'widgetTextColor': PropertySchema( r'widgetTextColor': PropertySchema(
id: 17, id: 18,
name: r'widgetTextColor', name: r'widgetTextColor',
type: IsarType.string, type: IsarType.string,
), ),
r'wind': PropertySchema( r'wind': PropertySchema(
id: 18, id: 19,
name: r'wind', name: r'wind',
type: IsarType.string, type: IsarType.string,
) )
@ -185,23 +190,24 @@ void _settingsSerialize(
) { ) {
writer.writeBool(offsets[0], object.amoledTheme); writer.writeBool(offsets[0], object.amoledTheme);
writer.writeString(offsets[1], object.degrees); writer.writeString(offsets[1], object.degrees);
writer.writeString(offsets[2], object.language); writer.writeBool(offsets[2], object.hideMap);
writer.writeBool(offsets[3], object.largeElement); writer.writeString(offsets[3], object.language);
writer.writeBool(offsets[4], object.location); writer.writeBool(offsets[4], object.largeElement);
writer.writeBool(offsets[5], object.materialColor); writer.writeBool(offsets[5], object.location);
writer.writeString(offsets[6], object.measurements); writer.writeBool(offsets[6], object.materialColor);
writer.writeBool(offsets[7], object.notifications); writer.writeString(offsets[7], object.measurements);
writer.writeBool(offsets[8], object.onboard); writer.writeBool(offsets[8], object.notifications);
writer.writeString(offsets[9], object.pressure); writer.writeBool(offsets[9], object.onboard);
writer.writeBool(offsets[10], object.roundDegree); writer.writeString(offsets[10], object.pressure);
writer.writeString(offsets[11], object.theme); writer.writeBool(offsets[11], object.roundDegree);
writer.writeString(offsets[12], object.timeEnd); writer.writeString(offsets[12], object.theme);
writer.writeLong(offsets[13], object.timeRange); writer.writeString(offsets[13], object.timeEnd);
writer.writeString(offsets[14], object.timeStart); writer.writeLong(offsets[14], object.timeRange);
writer.writeString(offsets[15], object.timeformat); writer.writeString(offsets[15], object.timeStart);
writer.writeString(offsets[16], object.widgetBackgroundColor); writer.writeString(offsets[16], object.timeformat);
writer.writeString(offsets[17], object.widgetTextColor); writer.writeString(offsets[17], object.widgetBackgroundColor);
writer.writeString(offsets[18], object.wind); writer.writeString(offsets[18], object.widgetTextColor);
writer.writeString(offsets[19], object.wind);
} }
Settings _settingsDeserialize( Settings _settingsDeserialize(
@ -213,24 +219,25 @@ Settings _settingsDeserialize(
final object = Settings(); final object = Settings();
object.amoledTheme = reader.readBool(offsets[0]); object.amoledTheme = reader.readBool(offsets[0]);
object.degrees = reader.readString(offsets[1]); object.degrees = reader.readString(offsets[1]);
object.hideMap = reader.readBool(offsets[2]);
object.id = id; object.id = id;
object.language = reader.readStringOrNull(offsets[2]); object.language = reader.readStringOrNull(offsets[3]);
object.largeElement = reader.readBool(offsets[3]); object.largeElement = reader.readBool(offsets[4]);
object.location = reader.readBool(offsets[4]); object.location = reader.readBool(offsets[5]);
object.materialColor = reader.readBool(offsets[5]); object.materialColor = reader.readBool(offsets[6]);
object.measurements = reader.readString(offsets[6]); object.measurements = reader.readString(offsets[7]);
object.notifications = reader.readBool(offsets[7]); object.notifications = reader.readBool(offsets[8]);
object.onboard = reader.readBool(offsets[8]); object.onboard = reader.readBool(offsets[9]);
object.pressure = reader.readString(offsets[9]); object.pressure = reader.readString(offsets[10]);
object.roundDegree = reader.readBool(offsets[10]); object.roundDegree = reader.readBool(offsets[11]);
object.theme = reader.readStringOrNull(offsets[11]); object.theme = reader.readStringOrNull(offsets[12]);
object.timeEnd = reader.readStringOrNull(offsets[12]); object.timeEnd = reader.readStringOrNull(offsets[13]);
object.timeRange = reader.readLongOrNull(offsets[13]); object.timeRange = reader.readLongOrNull(offsets[14]);
object.timeStart = reader.readStringOrNull(offsets[14]); object.timeStart = reader.readStringOrNull(offsets[15]);
object.timeformat = reader.readString(offsets[15]); object.timeformat = reader.readString(offsets[16]);
object.widgetBackgroundColor = reader.readStringOrNull(offsets[16]); object.widgetBackgroundColor = reader.readStringOrNull(offsets[17]);
object.widgetTextColor = reader.readStringOrNull(offsets[17]); object.widgetTextColor = reader.readStringOrNull(offsets[18]);
object.wind = reader.readString(offsets[18]); object.wind = reader.readString(offsets[19]);
return object; return object;
} }
@ -246,38 +253,40 @@ P _settingsDeserializeProp<P>(
case 1: case 1:
return (reader.readString(offset)) as P; return (reader.readString(offset)) as P;
case 2: case 2:
return (reader.readStringOrNull(offset)) as P;
case 3:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 3:
return (reader.readStringOrNull(offset)) as P;
case 4: case 4:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 5: case 5:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 6: case 6:
return (reader.readString(offset)) as P;
case 7:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 7:
return (reader.readString(offset)) as P;
case 8: case 8:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 9: case 9:
return (reader.readString(offset)) as P;
case 10:
return (reader.readBool(offset)) as P; return (reader.readBool(offset)) as P;
case 10:
return (reader.readString(offset)) as P;
case 11: case 11:
return (reader.readStringOrNull(offset)) as P; return (reader.readBool(offset)) as P;
case 12: case 12:
return (reader.readStringOrNull(offset)) as P; return (reader.readStringOrNull(offset)) as P;
case 13: case 13:
return (reader.readLongOrNull(offset)) as P; return (reader.readStringOrNull(offset)) as P;
case 14: case 14:
return (reader.readStringOrNull(offset)) as P; return (reader.readLongOrNull(offset)) as P;
case 15: case 15:
return (reader.readString(offset)) as P;
case 16:
return (reader.readStringOrNull(offset)) as P; return (reader.readStringOrNull(offset)) as P;
case 16:
return (reader.readString(offset)) as P;
case 17: case 17:
return (reader.readStringOrNull(offset)) as P; return (reader.readStringOrNull(offset)) as P;
case 18: case 18:
return (reader.readStringOrNull(offset)) as P;
case 19:
return (reader.readString(offset)) as P; return (reader.readString(offset)) as P;
default: default:
throw IsarError('Unknown property with id $propertyId'); throw IsarError('Unknown property with id $propertyId');
@ -513,6 +522,16 @@ extension SettingsQueryFilter
}); });
} }
QueryBuilder<Settings, Settings, QAfterFilterCondition> hideMapEqualTo(
bool value) {
return QueryBuilder.apply(this, (query) {
return query.addFilterCondition(FilterCondition.equalTo(
property: r'hideMap',
value: value,
));
});
}
QueryBuilder<Settings, Settings, QAfterFilterCondition> idEqualTo(Id value) { QueryBuilder<Settings, Settings, QAfterFilterCondition> idEqualTo(Id value) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addFilterCondition(FilterCondition.equalTo( return query.addFilterCondition(FilterCondition.equalTo(
@ -2145,6 +2164,18 @@ extension SettingsQuerySortBy on QueryBuilder<Settings, Settings, QSortBy> {
}); });
} }
QueryBuilder<Settings, Settings, QAfterSortBy> sortByHideMap() {
return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'hideMap', Sort.asc);
});
}
QueryBuilder<Settings, Settings, QAfterSortBy> sortByHideMapDesc() {
return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'hideMap', Sort.desc);
});
}
QueryBuilder<Settings, Settings, QAfterSortBy> sortByLanguage() { QueryBuilder<Settings, Settings, QAfterSortBy> sortByLanguage() {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'language', Sort.asc); return query.addSortBy(r'language', Sort.asc);
@ -2377,6 +2408,18 @@ extension SettingsQuerySortThenBy
}); });
} }
QueryBuilder<Settings, Settings, QAfterSortBy> thenByHideMap() {
return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'hideMap', Sort.asc);
});
}
QueryBuilder<Settings, Settings, QAfterSortBy> thenByHideMapDesc() {
return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'hideMap', Sort.desc);
});
}
QueryBuilder<Settings, Settings, QAfterSortBy> thenById() { QueryBuilder<Settings, Settings, QAfterSortBy> thenById() {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addSortBy(r'id', Sort.asc); return query.addSortBy(r'id', Sort.asc);
@ -2610,6 +2653,12 @@ extension SettingsQueryWhereDistinct
}); });
} }
QueryBuilder<Settings, Settings, QDistinct> distinctByHideMap() {
return QueryBuilder.apply(this, (query) {
return query.addDistinctBy(r'hideMap');
});
}
QueryBuilder<Settings, Settings, QDistinct> distinctByLanguage( QueryBuilder<Settings, Settings, QDistinct> distinctByLanguage(
{bool caseSensitive = true}) { {bool caseSensitive = true}) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
@ -2745,6 +2794,12 @@ extension SettingsQueryProperty
}); });
} }
QueryBuilder<Settings, bool, QQueryOperations> hideMapProperty() {
return QueryBuilder.apply(this, (query) {
return query.addPropertyName(r'hideMap');
});
}
QueryBuilder<Settings, String?, QQueryOperations> languageProperty() { QueryBuilder<Settings, String?, QQueryOperations> languageProperty() {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addPropertyName(r'language'); return query.addPropertyName(r'language');

View file

@ -30,31 +30,43 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
final weatherController = Get.put(WeatherController()); final weatherController = Get.put(WeatherController());
final _controller = TextEditingController(); final _controller = TextEditingController();
final pages = [ final List<Widget> pages = [
const WeatherPage(), const WeatherPage(),
const ListWeatherCard(), const ListWeatherCard(),
const MapWeather(), if (!settings.hideMap) const MapWeather(),
const SettingsPage(), const SettingsPage(),
]; ];
@override @override
void initState() { void initState() {
super.initState();
getData(); getData();
setupTabController();
}
@override
void dispose() {
tabController.dispose();
super.dispose();
}
void setupTabController() {
tabController = TabController( tabController = TabController(
initialIndex: tabIndex, initialIndex: tabIndex,
length: pages.length, length: pages.length,
vsync: this, vsync: this,
); );
tabController.animation?.addListener(() { tabController.animation?.addListener(() {
int value = (tabController.animation!.value).round(); int value = (tabController.animation!.value).round();
if (value != tabIndex) setState(() => tabIndex = value); if (value != tabIndex) setState(() => tabIndex = value);
}); });
tabController.addListener(() { tabController.addListener(() {
setState(() { setState(() {
tabIndex = tabController.index; tabIndex = tabController.index;
}); });
}); });
super.initState();
} }
void getData() async { void getData() async {
@ -199,10 +211,15 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
'cities'.tr, 'cities'.tr,
style: textStyle, style: textStyle,
), ),
2 => Text( 2 => settings.hideMap
'map'.tr, ? Text(
style: textStyle, 'settings_full'.tr,
), style: textStyle,
)
: Text(
'map'.tr,
style: textStyle,
),
3 => Text( 3 => Text(
'settings_full'.tr, 'settings_full'.tr,
style: textStyle, style: textStyle,
@ -253,11 +270,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
selectedIcon: const Icon(IconsaxPlusBold.buildings), selectedIcon: const Icon(IconsaxPlusBold.buildings),
label: 'cities'.tr, label: 'cities'.tr,
), ),
NavigationDestination( if (!settings.hideMap)
icon: const Icon(IconsaxPlusLinear.map), NavigationDestination(
selectedIcon: const Icon(IconsaxPlusBold.map), icon: const Icon(IconsaxPlusLinear.map),
label: 'map'.tr, selectedIcon: const Icon(IconsaxPlusBold.map),
), label: 'map'.tr,
),
NavigationDestination( NavigationDestination(
icon: const Icon(IconsaxPlusLinear.category), icon: const Icon(IconsaxPlusLinear.category),
selectedIcon: const Icon(IconsaxPlusBold.category), selectedIcon: const Icon(IconsaxPlusBold.category),

View file

@ -18,6 +18,7 @@ import 'package:rain/app/modules/settings/widgets/setting_card.dart';
import 'package:rain/main.dart'; import 'package:rain/main.dart';
import 'package:rain/theme/theme_controller.dart'; import 'package:rain/theme/theme_controller.dart';
import 'package:rain/utils/color_converter.dart'; import 'package:rain/utils/color_converter.dart';
import 'package:restart_app/restart_app.dart';
class SettingsPage extends StatefulWidget { class SettingsPage extends StatefulWidget {
const SettingsPage({super.key}); const SettingsPage({super.key});
@ -844,47 +845,109 @@ class _SettingsPageState extends State<SettingsPage> {
}, },
), ),
SettingCard( SettingCard(
icon: const Icon(IconsaxPlusLinear.trash_square), icon: const Icon(IconsaxPlusLinear.map),
text: 'clearCacheStore'.tr, text: 'map'.tr,
onPressed: () => showAdaptiveDialog( onPressed: () {
context: context, showModalBottomSheet(
builder: (context) => AlertDialog.adaptive( context: context,
title: Text( builder: (BuildContext context) {
'deletedCacheStore'.tr, return Padding(
style: context.textTheme.titleLarge, padding: EdgeInsets.only(
), bottom: MediaQuery.of(context).padding.bottom),
content: Text( child: StatefulBuilder(
'deletedCacheStoreQuery'.tr, builder: (BuildContext context, setState) {
style: context.textTheme.titleMedium, return SingleChildScrollView(
), child: Column(
actions: [ crossAxisAlignment: CrossAxisAlignment.center,
TextButton( mainAxisSize: MainAxisSize.min,
onPressed: () => Get.back(), children: [
child: Text( Padding(
'cancel'.tr, padding:
style: context.textTheme.titleMedium?.copyWith( const EdgeInsets.symmetric(vertical: 15),
color: Colors.blueAccent, 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),
],
),
);
},
), ),
), );
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,
),
),
),
],
),
),
), ),
SettingCard( SettingCard(
icon: const Icon(IconsaxPlusLinear.language_square), icon: const Icon(IconsaxPlusLinear.language_square),

View file

@ -449,10 +449,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_timezone name: flutter_timezone
sha256: "06150cc6dde7a0309acc3f1c38380819ae774be4d942934c824c4fa64efadffa" sha256: ea53c61c9152f271a5e30624a624184804947b6a733ff2b64186bb2579446892
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.0" version: "3.0.1"
flutter_web_plugins: flutter_web_plugins:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -1010,6 +1010,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.0" 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: scrollable_positioned_list:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -24,6 +24,7 @@ dependencies:
geolocator: ^13.0.1 geolocator: ^13.0.1
home_widget: ^0.7.0 home_widget: ^0.7.0
workmanager: ^0.5.2 workmanager: ^0.5.2
restart_app: ^1.2.1
flutter_map: ^7.0.2 flutter_map: ^7.0.2
google_fonts: ^6.2.1 google_fonts: ^6.2.1
url_launcher: ^6.3.0 url_launcher: ^6.3.0
@ -33,7 +34,7 @@ dependencies:
path_provider: ^2.1.4 path_provider: ^2.1.4
# quick_settings: ^1.0.1 # quick_settings: ^1.0.1
json_annotation: ^4.9.0 json_annotation: ^4.9.0
flutter_timezone: ^3.0.0 flutter_timezone: ^3.0.1
device_info_plus: ^10.1.2 device_info_plus: ^10.1.2
package_info_plus: ^8.0.2 package_info_plus: ^8.0.2
connectivity_plus: ^6.0.5 connectivity_plus: ^6.0.5