This repository has been archived on 2023-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
meincantor-app/lib/Settings/Pages/plan_settings.dart
Denys Konovalov 6ad143195a ==0.7.5==
- added A LOT, TLTD
Settings menu, updated homepage tiles, added color settings...
- TODO:
  - update README
  - update license & copyright info
  - cleanup code
  - merge code parts to server side
  - complete settings
  - fix 11/12
  - add caching
  - muuuuuuuch more...
2021-11-06 11:01:44 +01:00

177 lines
7.0 KiB
Dart

import 'dart:convert';
import 'package:MeinCantor/main.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cyclop/cyclop.dart';
import 'package:MeinCantor/networking.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../color_presets.dart';
import 'package:MeinCantor/subject_presets.dart';
import '../../teacher_presets.dart';
class PlanSettings extends StatefulWidget {
const PlanSettings({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _PlanSettingsState();
}
Future<Color> buildPlanColors(lesson) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey("color$lesson")) {
prefs.setInt("color$lesson", colors[lesson].value ?? Colors.grey.value);
}
await fetchLessonList();
Color colorDeu = Color(prefs.getInt("color$lesson")!);
return colorDeu;
}
Future<List<dynamic>> buildLessonsList() async {
await fetchLessonList();
SharedPreferences prefs = await SharedPreferences.getInstance();
String lessonsJson = prefs.getString("lessons")!;
List<dynamic> lessons = jsonDecode(lessonsJson);
return lessons;
}
class _PlanSettingsState extends State<PlanSettings> {
Set<Color> swatches = {...Colors.primaries, ...Colors.accents, Palette.accent, Palette.primary};
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Plan"),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
children: [
const ListTile(
title: Text("Kurse/Fächer"),
leading: Icon(Icons.list_alt_outlined),
),
FutureBuilder(
future: buildLessonsList(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Widget> children = [];
for (var element in (snapshot.data as List<dynamic>)) {
String subject = element['subject'];
String teacher = element['teacher'];
children.add(FutureBuilder(
future: buildPlanColors(subject),
builder: (context, snapshot) {
if (snapshot.hasData) {
Color color = snapshot.data as Color;
return ListTile(
leading: ColorButton(
key: const Key('c1'),
color: color,
config: const ColorPickerConfig(
enableEyePicker: false),
onSwatchesChanged: (Set<Color> value) {
swatches = value;
},
size: 32,
swatches: swatches,
onColorChanged: (Color value) async {
setState(() {
color = value;
});
SharedPreferences prefs = await SharedPreferences
.getInstance();
prefs.setInt(
"color$subject", value.value);
}
),
title: Text(names[subject] ?? ""),
subtitle: Text(teachers[teacher] ?? ""),
);
} else {
return (const LinearProgressIndicator());
}
}
),
);
}
return Column(
children: children,
);
} else {
return (const Center(
child: CircularProgressIndicator()));
}
}
),
/*FutureBuilder(
future: buildPlanColors("Mat"),
builder: (context, snapshot) {
if (snapshot.hasData) {
Color color = snapshot.data as Color;
return ListTile(
leading: ColorButton(
key: const Key('c1'),
color: color,
//boxShape: BoxShape.circle, // default : circle
config: const ColorPickerConfig(enableEyePicker: false),
onSwatchesChanged: (Set<Color> value) {
swatches = value;
},
size: 32,
swatches: swatches,
onColorChanged: (Color value) async {
setState(() {
color = value;
});
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt("colorMat", value.value);
}
),
title: const Text("Mathematik"),
);
} else {
return (const Center(child: CircularProgressIndicator()));
}
}
),
FutureBuilder(
future: buildPlanColors("Bio"),
builder: (context, snapshot) {
if (snapshot.hasData) {
Color color = snapshot.data as Color;
return ListTile(
leading: ColorButton(
key: const Key('c1'),
color: color,
//boxShape: BoxShape.circle, // default : circle
config: const ColorPickerConfig(enableEyePicker: false),
onSwatchesChanged: (Set<Color> value) {
swatches = value;
},
size: 32,
swatches: swatches,
onColorChanged: (Color value) async {
setState(() {
color = value;
});
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt("colorBio", value.value);
}
),
title: const Text("Biologie"),
);
} else {
return (const Center(child: CircularProgressIndicator()));
}
}
),*/
],
)
);
}
}