rounding shits
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
// ignore_for_file: prefer_function_declarations_over_variables, library_private_types_in_public_api
|
||||
// ignore_for_file: prefer_function_declarations_over_variables, library_private_types_in_public_api, use_build_context_synchronously
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/helpers/quick_actions.dart';
|
||||
import 'package:filcnaplo/icons/filc_icons.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||
import 'package:filcnaplo/theme/observer.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/grade.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/subject.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/absence_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu_item.dart';
|
||||
@@ -179,6 +184,18 @@ class SettingsHelper {
|
||||
);
|
||||
}
|
||||
|
||||
// new v5 roundings
|
||||
static void newRoundings(BuildContext context, GradeSubject subject) {
|
||||
showRoundedModalBottomSheet(
|
||||
context,
|
||||
child: RoundingSetting(
|
||||
rounding: subject.customRounding,
|
||||
subjectId: subject.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
// end
|
||||
|
||||
static void theme(BuildContext context) {
|
||||
var settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
void Function(ThemeMode) setTheme = (mode) {
|
||||
@@ -353,7 +370,7 @@ class SettingsHelper {
|
||||
setSystemChrome(context);
|
||||
});
|
||||
},
|
||||
title: Text("add_user"),
|
||||
title: const Text("add_user"),
|
||||
leading: const Icon(FeatherIcons.userPlus),
|
||||
);
|
||||
} else {
|
||||
@@ -366,7 +383,10 @@ class SettingsHelper {
|
||||
|
||||
// Rounding modal
|
||||
class RoundingSetting extends StatefulWidget {
|
||||
const RoundingSetting({super.key});
|
||||
const RoundingSetting({super.key, this.rounding, this.subjectId});
|
||||
|
||||
final double? rounding;
|
||||
final String? subjectId;
|
||||
|
||||
@override
|
||||
_RoundingSettingState createState() => _RoundingSettingState();
|
||||
@@ -378,12 +398,19 @@ class _RoundingSettingState extends State<RoundingSetting> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
rounding =
|
||||
Provider.of<SettingsProvider>(context, listen: false).rounding / 10;
|
||||
|
||||
rounding = (widget.rounding ??
|
||||
Provider.of<SettingsProvider>(context, listen: false).rounding) /
|
||||
10;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UserProvider userProvider =
|
||||
Provider.of<UserProvider>(context, listen: false);
|
||||
DatabaseProvider databaseProvider =
|
||||
Provider.of<DatabaseProvider>(context, listen: false);
|
||||
|
||||
int roundingResult;
|
||||
|
||||
if (4.5 >= 4.5.floor() + rounding) {
|
||||
@@ -438,10 +465,32 @@ class _RoundingSettingState extends State<RoundingSetting> {
|
||||
padding: const EdgeInsets.only(bottom: 12.0, top: 6.0),
|
||||
child: MaterialActionButton(
|
||||
child: Text(SettingsLocalization("done").i18n),
|
||||
onPressed: () {
|
||||
Provider.of<SettingsProvider>(context, listen: false)
|
||||
.update(rounding: (rounding * 10).toInt());
|
||||
Navigator.of(context).maybePop();
|
||||
onPressed: () async {
|
||||
if (widget.rounding == null) {
|
||||
Provider.of<SettingsProvider>(context, listen: false)
|
||||
.update(rounding: (rounding * 10).toInt());
|
||||
} else {
|
||||
Map<String, String> roundings = await databaseProvider.userQuery
|
||||
.getRoundings(userId: userProvider.id!);
|
||||
|
||||
roundings[widget.subjectId!] = (rounding * 10).toStringAsFixed(2);
|
||||
|
||||
await databaseProvider.userStore
|
||||
.storeRoundings(roundings, userId: userProvider.id!);
|
||||
|
||||
await Provider.of<GradeProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
await Provider.of<TimetableProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
await Provider.of<AbsenceProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
}
|
||||
|
||||
// ik i'm like a kreta dev, but setstate isn't working, so please don't kill me bye :3
|
||||
// actually it also looks good and it's kinda useful
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
// setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user