Added license settings card

This commit is contained in:
Shatanik Mahanty 2023-10-10 14:33:26 +05:30
parent 8a697af1de
commit 7e9be7421f

View file

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:geolocator/geolocator.dart';
@ -87,18 +88,13 @@ class _SettingsPageState extends State<SettingsPage> {
text: 'theme'.tr,
dropdown: true,
dropdownName: settings.theme?.tr,
dropdownList: <String>[
'system'.tr,
'dark'.tr,
'light'.tr
],
dropdownList: <String>['system'.tr, 'dark'.tr, 'light'.tr],
dropdownCange: (String? newValue) {
ThemeMode themeMode =
newValue?.tr == 'system'.tr
? ThemeMode.system
: newValue?.tr == 'dark'.tr
? ThemeMode.dark
: ThemeMode.light;
ThemeMode themeMode = newValue?.tr == 'system'.tr
? ThemeMode.system
: newValue?.tr == 'dark'.tr
? ThemeMode.dark
: ThemeMode.light;
String theme = newValue?.tr == 'system'.tr
? 'system'
: newValue?.tr == 'dark'.tr
@ -117,8 +113,7 @@ class _SettingsPageState extends State<SettingsPage> {
value: settings.amoledTheme,
onChange: (value) {
themeController.saveOledTheme(value);
MyApp.updateAppState(context,
newAmoledTheme: value);
MyApp.updateAppState(context, newAmoledTheme: value);
},
),
SettingCard(
@ -129,8 +124,7 @@ class _SettingsPageState extends State<SettingsPage> {
value: settings.materialColor,
onChange: (value) {
themeController.saveMaterialTheme(value);
MyApp.updateAppState(context,
newMaterialColor: value);
MyApp.updateAppState(context, newMaterialColor: value);
},
),
const SizedBox(height: 10),
@ -174,8 +168,7 @@ class _SettingsPageState extends State<SettingsPage> {
value: settings.location,
onChange: (value) async {
if (value) {
bool serviceEnabled = await Geolocator
.isLocationServiceEnabled();
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
if (!mounted) return;
await showAdaptiveDialog(
@ -186,31 +179,21 @@ class _SettingsPageState extends State<SettingsPage> {
'location'.tr,
style: context.textTheme.titleLarge,
),
content: Text('no_location'.tr,
style: context
.textTheme.titleMedium),
content: Text('no_location'.tr, style: context.textTheme.titleMedium),
actions: [
TextButton(
onPressed: () =>
Get.back(result: false),
onPressed: () => Get.back(result: false),
child: Text('cancel'.tr,
style: context.theme
.textTheme.titleMedium
?.copyWith(
color: Colors
.blueAccent))),
style: context.theme.textTheme.titleMedium
?.copyWith(color: Colors.blueAccent))),
TextButton(
onPressed: () {
Geolocator
.openLocationSettings();
Geolocator.openLocationSettings();
Get.back(result: true);
},
child: Text('settings'.tr,
style: context.theme
.textTheme.titleMedium
?.copyWith(
color:
Colors.green))),
style: context.theme.textTheme.titleMedium
?.copyWith(color: Colors.green))),
],
);
},
@ -234,19 +217,15 @@ class _SettingsPageState extends State<SettingsPage> {
switcher: true,
value: settings.notifications,
onChange: (value) async {
final resultExact =
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestExactAlarmsPermission();
final resultExact = await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
?.requestExactAlarmsPermission();
final result = Platform.isIOS
? await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions()
: await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission();
if (result != null && resultExact != null) {
isar.writeTxnSync(() {
@ -254,8 +233,7 @@ class _SettingsPageState extends State<SettingsPage> {
isar.settings.putSync(settings);
});
if (value) {
weatherController.notlification(
weatherController.mainWeather);
weatherController.notlification(weatherController.mainWeather);
} else {
flutterLocalNotificationsPlugin.cancelAll();
}
@ -281,12 +259,10 @@ class _SettingsPageState extends State<SettingsPage> {
settings.timeRange = int.parse(newValue!);
isar.settings.putSync(settings);
});
MyApp.updateAppState(context,
newTimeRange: int.parse(newValue!));
MyApp.updateAppState(context, newTimeRange: int.parse(newValue!));
if (settings.notifications) {
flutterLocalNotificationsPlugin.cancelAll();
weatherController.notlification(
weatherController.mainWeather);
weatherController.notlification(weatherController.mainWeather);
}
},
),
@ -297,27 +273,18 @@ class _SettingsPageState extends State<SettingsPage> {
info: true,
infoSettings: true,
textInfo: settings.timeformat == '12'
? DateFormat.jm().format(DateFormat.Hm()
.parse(weatherController
.timeConvert(timeStart)
.format(context)))
: DateFormat.Hm().format(DateFormat.Hm()
.parse(weatherController
.timeConvert(timeStart)
.format(context))),
? DateFormat.jm().format(
DateFormat.Hm().parse(weatherController.timeConvert(timeStart).format(context)))
: DateFormat.Hm().format(
DateFormat.Hm().parse(weatherController.timeConvert(timeStart).format(context))),
onPressed: () async {
final TimeOfDay? timeStartPicker =
await showTimePicker(
final TimeOfDay? timeStartPicker = await showTimePicker(
context: context,
initialTime:
weatherController.timeConvert(timeStart),
initialTime: weatherController.timeConvert(timeStart),
builder: (context, child) {
final Widget mediaQueryWrapper = MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
settings.timeformat == '12'
? false
: true,
alwaysUse24HourFormat: settings.timeformat == '12' ? false : true,
),
child: child!,
);
@ -326,18 +293,14 @@ class _SettingsPageState extends State<SettingsPage> {
);
if (timeStartPicker != null) {
isar.writeTxnSync(() {
settings.timeStart =
timeStartPicker.format(context);
settings.timeStart = timeStartPicker.format(context);
isar.settings.putSync(settings);
});
if (!mounted) return;
MyApp.updateAppState(context,
newTimeStart:
timeStartPicker.format(context));
MyApp.updateAppState(context, newTimeStart: timeStartPicker.format(context));
if (settings.notifications) {
flutterLocalNotificationsPlugin.cancelAll();
weatherController.notlification(
weatherController.mainWeather);
weatherController.notlification(weatherController.mainWeather);
}
}
},
@ -349,27 +312,18 @@ class _SettingsPageState extends State<SettingsPage> {
info: true,
infoSettings: true,
textInfo: settings.timeformat == '12'
? DateFormat.jm().format(DateFormat.Hm()
.parse(weatherController
.timeConvert(timeEnd)
.format(context)))
: DateFormat.Hm().format(DateFormat.Hm()
.parse(weatherController
.timeConvert(timeEnd)
.format(context))),
? DateFormat.jm().format(
DateFormat.Hm().parse(weatherController.timeConvert(timeEnd).format(context)))
: DateFormat.Hm().format(
DateFormat.Hm().parse(weatherController.timeConvert(timeEnd).format(context))),
onPressed: () async {
final TimeOfDay? timeEndPicker =
await showTimePicker(
final TimeOfDay? timeEndPicker = await showTimePicker(
context: context,
initialTime:
weatherController.timeConvert(timeEnd),
initialTime: weatherController.timeConvert(timeEnd),
builder: (context, child) {
final Widget mediaQueryWrapper = MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
settings.timeformat == '12'
? false
: true,
alwaysUse24HourFormat: settings.timeformat == '12' ? false : true,
),
child: child!,
);
@ -378,18 +332,14 @@ class _SettingsPageState extends State<SettingsPage> {
);
if (timeEndPicker != null) {
isar.writeTxnSync(() {
settings.timeEnd =
timeEndPicker.format(context);
settings.timeEnd = timeEndPicker.format(context);
isar.settings.putSync(settings);
});
if (!mounted) return;
MyApp.updateAppState(context,
newTimeEnd:
timeEndPicker.format(context));
MyApp.updateAppState(context, newTimeEnd: timeEndPicker.format(context));
if (settings.notifications) {
flutterLocalNotificationsPlugin.cancelAll();
weatherController.notlification(
weatherController.mainWeather);
weatherController.notlification(weatherController.mainWeather);
}
}
},
@ -433,15 +383,10 @@ class _SettingsPageState extends State<SettingsPage> {
text: 'degrees'.tr,
dropdown: true,
dropdownName: settings.degrees.tr,
dropdownList: <String>[
'celsius'.tr,
'fahrenheit'.tr
],
dropdownList: <String>['celsius'.tr, 'fahrenheit'.tr],
dropdownCange: (String? newValue) async {
isar.writeTxnSync(() {
settings.degrees = newValue == 'celsius'.tr
? 'celsius'
: 'fahrenheit';
settings.degrees = newValue == 'celsius'.tr ? 'celsius' : 'fahrenheit';
isar.settings.putSync(settings);
});
await weatherController.deleteAll(false);
@ -456,16 +401,10 @@ class _SettingsPageState extends State<SettingsPage> {
text: 'measurements'.tr,
dropdown: true,
dropdownName: settings.measurements.tr,
dropdownList: <String>[
'metric'.tr,
'imperial'.tr
],
dropdownList: <String>['metric'.tr, 'imperial'.tr],
dropdownCange: (String? newValue) async {
isar.writeTxnSync(() {
settings.measurements =
newValue == 'metric'.tr
? 'metric'
: 'imperial';
settings.measurements = newValue == 'metric'.tr ? 'metric' : 'imperial';
isar.settings.putSync(settings);
});
await weatherController.deleteAll(false);
@ -483,8 +422,7 @@ class _SettingsPageState extends State<SettingsPage> {
dropdownList: <String>['12'.tr, '24'.tr],
dropdownCange: (String? newValue) {
isar.writeTxnSync(() {
settings.timeformat =
newValue == '12'.tr ? '12' : '24';
settings.timeformat = newValue == '12'.tr ? '12' : '24';
isar.settings.putSync(settings);
});
setState(() {});
@ -505,8 +443,7 @@ class _SettingsPageState extends State<SettingsPage> {
text: 'language'.tr,
info: true,
infoSettings: true,
textInfo: appLanguages.firstWhere(
(element) => (element['locale'] == locale),
textInfo: appLanguages.firstWhere((element) => (element['locale'] == locale),
orElse: () => appLanguages.first)['name'],
onPressed: () {
showModalBottomSheet(
@ -533,8 +470,7 @@ class _SettingsPageState extends State<SettingsPage> {
itemBuilder: (context, index) {
return Card(
elevation: 4,
margin: const EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: ListTile(
title: Text(
appLanguages[index]['name'],
@ -542,11 +478,8 @@ class _SettingsPageState extends State<SettingsPage> {
textAlign: TextAlign.center,
),
onTap: () {
MyApp.updateAppState(context,
newLocale: appLanguages[index]
['locale']);
updateLanguage(
appLanguages[index]['locale']);
MyApp.updateAppState(context, newLocale: appLanguages[index]['locale']);
updateLanguage(appLanguages[index]['locale']);
},
),
);
@ -588,15 +521,13 @@ class _SettingsPageState extends State<SettingsPage> {
elevation: 4,
icon: const Icon(Iconsax.card),
text: 'DonationAlerts',
onPressed: () => urlLauncher(
'https://www.donationalerts.com/r/yoshimok'),
onPressed: () => urlLauncher('https://www.donationalerts.com/r/yoshimok'),
),
SettingCard(
elevation: 4,
icon: const Icon(Iconsax.wallet),
text: 'ЮMoney',
onPressed: () => urlLauncher(
'https://yoomoney.ru/to/4100117672775961'),
onPressed: () => urlLauncher('https://yoomoney.ru/to/4100117672775961'),
),
const SizedBox(height: 10),
],
@ -620,8 +551,24 @@ class _SettingsPageState extends State<SettingsPage> {
scale: 20,
),
text: '${'project'.tr} GitHub',
onPressed: () =>
urlLauncher('https://github.com/DarkMooNight/Rain'),
onPressed: () => urlLauncher('https://github.com/DarkMooNight/Rain'),
),
SettingCard(
icon: const Icon(Iconsax.document),
text: 'license'.tr,
onPressed: () => Get.to(
LicensePage(
applicationIcon: const SizedBox(
width: 100,
height: 100,
child: Image(
image: AssetImage('assets/icons/icon.png'),
),
),
applicationName: 'Rain',
applicationVersion: appVersion,
),
),
),
],
),