2023-10-19 21:45:07 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
2023-10-25 23:00:47 +00:00
|
|
|
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
2023-10-19 21:45:07 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
|
|
|
late String oldWindowTitle;
|
2023-10-25 23:00:47 +00:00
|
|
|
Color pickerColor = Colors.cyanAccent;
|
|
|
|
Color currentColor = Colors.cyanAccent;
|
2023-10-19 21:45:07 +00:00
|
|
|
|
|
|
|
class CustomizationView extends StatefulWidget {
|
|
|
|
const CustomizationView({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => CustomizationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomizationState extends State<CustomizationView> {
|
|
|
|
late SharedPreferences prefs;
|
|
|
|
|
2023-10-25 23:00:47 +00:00
|
|
|
void changeColor(Color color) {
|
|
|
|
setState(() => pickerColor = color);
|
|
|
|
}
|
|
|
|
|
2023-10-19 21:45:07 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-10-25 23:00:47 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) {
|
2023-10-19 21:45:07 +00:00
|
|
|
windowManager.getTitle().then((value) => oldWindowTitle = value);
|
|
|
|
windowManager.setTitle("Tetra Stats: ${t.settings}");
|
|
|
|
}
|
|
|
|
_getPreferences();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-10-25 23:00:47 +00:00
|
|
|
void dispose() {
|
2023-10-19 21:45:07 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) windowManager.setTitle(oldWindowTitle);
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _getPreferences() async {
|
|
|
|
prefs = await SharedPreferences.getInstance();
|
|
|
|
}
|
|
|
|
|
2023-10-25 23:00:47 +00:00
|
|
|
ThemeData getTheme(BuildContext context, Color color){
|
|
|
|
return Theme.of(context).copyWith();
|
|
|
|
}
|
|
|
|
|
2023-10-19 21:45:07 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final t = Translations.of(context);
|
2023-10-25 23:00:47 +00:00
|
|
|
List<DropdownMenuItem<AppLocale>>? locales =
|
|
|
|
<DropdownMenuItem<AppLocale>>[];
|
|
|
|
for (var v in AppLocale.values) {
|
2023-10-19 21:45:07 +00:00
|
|
|
locales.add(DropdownMenuItem<AppLocale>(
|
2023-10-25 23:00:47 +00:00
|
|
|
value: v, child: Text(t.locales[v.languageTag]!)));
|
2023-10-19 21:45:07 +00:00
|
|
|
}
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(t.settings),
|
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
2023-10-25 23:00:47 +00:00
|
|
|
body: Theme(
|
|
|
|
data: getTheme(context, currentColor),
|
|
|
|
child: SafeArea(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text("Accent Color"),
|
|
|
|
trailing: ColorIndicator(HSVColor.fromColor(Theme.of(context).primaryColorDark)),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AlertDialog(
|
|
|
|
title: const Text('Pick a color!'),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ColorPicker(
|
|
|
|
pickerColor: pickerColor,
|
|
|
|
onColorChanged: changeColor,
|
|
|
|
),
|
|
|
|
// Use Material color picker:
|
|
|
|
//
|
|
|
|
// child: MaterialPicker(
|
|
|
|
// pickerColor: pickerColor,
|
|
|
|
// onColorChanged: changeColor,
|
|
|
|
// showLabel: true, // only on portrait mode
|
|
|
|
// ),
|
|
|
|
//
|
|
|
|
// Use Block color picker:
|
|
|
|
//
|
|
|
|
// child: BlockPicker(
|
|
|
|
// pickerColor: currentColor,
|
|
|
|
// onColorChanged: changeColor,
|
|
|
|
// ),
|
|
|
|
//
|
|
|
|
// child: MultipleChoiceBlockPicker(
|
|
|
|
// pickerColors: currentColors,
|
|
|
|
// onColorsChanged: changeColors,
|
|
|
|
// ),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
ElevatedButton(
|
|
|
|
child: const Text('Got it'),
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
currentColor = pickerColor;
|
|
|
|
});
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]));
|
|
|
|
}),
|
|
|
|
ListTile(
|
|
|
|
title: Text("Font"),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text("Stats Table in TL mathes list"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
),
|
2023-10-19 21:45:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|