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 roundDegree = false;
bool largeElement = false;
bool hideMap = false;
String? widgetBackgroundColor;
String? widgetTextColor;
String measurements = 'metric';

View file

@ -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<P>(
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;
return (reader.readStringOrNull(offset)) as P;
case 14:
return (reader.readStringOrNull(offset)) as P;
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<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) {
return QueryBuilder.apply(this, (query) {
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() {
return QueryBuilder.apply(this, (query) {
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() {
return QueryBuilder.apply(this, (query) {
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(
{bool caseSensitive = true}) {
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() {
return QueryBuilder.apply(this, (query) {
return query.addPropertyName(r'language');

View file

@ -30,31 +30,43 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
final weatherController = Get.put(WeatherController());
final _controller = TextEditingController();
final pages = [
final List<Widget> 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,7 +211,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
'cities'.tr,
style: textStyle,
),
2 => Text(
2 => settings.hideMap
? Text(
'settings_full'.tr,
style: textStyle,
)
: Text(
'map'.tr,
style: textStyle,
),
@ -253,6 +270,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
selectedIcon: const Icon(IconsaxPlusBold.buildings),
label: 'cities'.tr,
),
if (!settings.hideMap)
NavigationDestination(
icon: const Icon(IconsaxPlusLinear.map),
selectedIcon: const Icon(IconsaxPlusBold.map),

View file

@ -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,7 +845,55 @@ class _SettingsPageState extends State<SettingsPage> {
},
),
SettingCard(
icon: const Icon(IconsaxPlusLinear.trash_square),
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,
@ -862,14 +911,16 @@ class _SettingsPageState extends State<SettingsPage> {
onPressed: () => Get.back(),
child: Text(
'cancel'.tr,
style: context.textTheme.titleMedium?.copyWith(
style: context.textTheme.titleMedium
?.copyWith(
color: Colors.blueAccent,
),
),
),
TextButton(
onPressed: () async {
final dir = await getTemporaryDirectory();
final dir =
await getTemporaryDirectory();
final cacheStoreFuture = FileCacheStore(
'${dir.path}${Platform.pathSeparator}MapTiles');
cacheStoreFuture.clean();
@ -877,7 +928,8 @@ class _SettingsPageState extends State<SettingsPage> {
},
child: Text(
'delete'.tr,
style: context.textTheme.titleMedium?.copyWith(
style: context.textTheme.titleMedium
?.copyWith(
color: Colors.red,
),
),
@ -886,6 +938,17 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
),
const Gap(10),
],
),
);
},
),
);
},
);
},
),
SettingCard(
icon: const Icon(IconsaxPlusLinear.language_square),
text: 'language'.tr,

View file

@ -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:

View file

@ -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