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(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/splitted_panel/splitted_panel.dart';
|
||||
import 'package:filcnaplo_mobile_ui/screens/settings/settings_helper.dart';
|
||||
// import 'package:filcnaplo_mobile_ui/screens/settings/settings_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -20,8 +20,11 @@ import 'package:provider/provider.dart';
|
||||
import 'edit_subject.i18n.dart';
|
||||
|
||||
class EditSubjectScreen extends StatefulWidget {
|
||||
const EditSubjectScreen(
|
||||
{super.key, required this.subject, required this.teacher});
|
||||
const EditSubjectScreen({
|
||||
super.key,
|
||||
required this.subject,
|
||||
required this.teacher,
|
||||
});
|
||||
|
||||
final GradeSubject subject;
|
||||
final Teacher teacher;
|
||||
@@ -139,38 +142,41 @@ class EditSubjectScreenState extends State<EditSubjectScreen> {
|
||||
],
|
||||
),
|
||||
// edit rounding
|
||||
SplittedPanel(
|
||||
padding: const EdgeInsets.only(top: 9.0),
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
isSeparated: true,
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: () {
|
||||
SettingsHelper.rounding(context);
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
"rounding".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Icon(
|
||||
FeatherIcons.gitCommit,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
trailing: Text(
|
||||
(settingsProvider.rounding / 10).toStringAsFixed(1),
|
||||
style: const TextStyle(fontSize: 14.0),
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// SplittedPanel(
|
||||
// padding: const EdgeInsets.only(top: 9.0),
|
||||
// cardPadding: const EdgeInsets.all(4.0),
|
||||
// isSeparated: true,
|
||||
// children: [
|
||||
// PanelButton(
|
||||
// onPressed: () {
|
||||
// SettingsHelper.newRoundings(context, widget.subject);
|
||||
// setState(() {});
|
||||
// },
|
||||
// title: Text(
|
||||
// "rounding".i18n,
|
||||
// style: TextStyle(
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// ),
|
||||
// leading: Icon(
|
||||
// FeatherIcons.gitCommit,
|
||||
// size: 22.0,
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// trailing: Text(
|
||||
// ((widget.subject.customRounding ??
|
||||
// settingsProvider.rounding) /
|
||||
// 10)
|
||||
// .toStringAsFixed(1),
|
||||
// style: const TextStyle(fontSize: 14.0),
|
||||
// ),
|
||||
// borderRadius: const BorderRadius.vertical(
|
||||
// top: Radius.circular(12.0),
|
||||
// bottom: Radius.circular(12.0),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/helpers/subject.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||
@@ -62,6 +63,7 @@ class PersonalizeSettingsScreen extends StatefulWidget {
|
||||
class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late SettingsProvider settingsProvider;
|
||||
late UserProvider user;
|
||||
|
||||
late AnimationController _hideContainersController;
|
||||
|
||||
@@ -179,6 +181,7 @@ class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
user = Provider.of<UserProvider>(context);
|
||||
|
||||
String themeModeText = {
|
||||
ThemeMode.light: "light".i18n,
|
||||
@@ -517,7 +520,7 @@ class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (String? v) {
|
||||
onChanged: (String? v) async {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => EditSubjectScreen(
|
||||
|
||||
Reference in New Issue
Block a user