2022-05-16 20:26:39 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-05-02 12:07:47 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-05-16 20:26:39 +02:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-05-09 16:55:20 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-05-16 20:26:39 +02:00
|
|
|
|
|
|
|
import '../lang/lang.dart';
|
2022-05-02 12:07:47 +02:00
|
|
|
|
|
|
|
class Nastaveni extends StatefulWidget {
|
|
|
|
const Nastaveni({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Nastaveni> createState() => _NastaveniState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NastaveniState extends State<Nastaveni> {
|
2022-05-09 16:55:20 +02:00
|
|
|
bool _ukladatOffline = false;
|
2022-05-16 20:26:39 +02:00
|
|
|
bool _preskakovatVikend = false;
|
2022-05-09 16:55:20 +02:00
|
|
|
|
|
|
|
void najitNastaveni() async {
|
|
|
|
var preferences = await SharedPreferences.getInstance();
|
2022-05-16 20:26:39 +02:00
|
|
|
setState(() {
|
|
|
|
_ukladatOffline = preferences.getBool("offline") ?? false;
|
|
|
|
_preskakovatVikend = preferences.getBool("skip") ?? false;
|
|
|
|
});
|
2022-05-09 16:55:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void zmenitNastaveni(String key, bool value) async {
|
|
|
|
var preferences = await SharedPreferences.getInstance();
|
|
|
|
preferences.setBool(key, value);
|
|
|
|
}
|
|
|
|
|
2022-05-16 20:26:39 +02:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
najitNastaveni();
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:07:47 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-05-09 16:55:20 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-05-16 20:26:39 +02:00
|
|
|
title: Text(Languages.of(context)!.settings),
|
2022-05-09 16:55:20 +02:00
|
|
|
),
|
|
|
|
body: Center(
|
2022-05-16 20:26:39 +02:00
|
|
|
child: SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width / 1.1,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(Languages.of(context)!.saveOffline),
|
|
|
|
Switch(
|
|
|
|
value: _ukladatOffline,
|
|
|
|
onChanged: (value) {
|
2022-05-20 08:03:53 +02:00
|
|
|
setState(() {
|
2022-05-16 20:26:39 +02:00
|
|
|
_ukladatOffline = value;
|
2022-05-20 08:03:53 +02:00
|
|
|
cistit(value);
|
2022-05-16 20:26:39 +02:00
|
|
|
zmenitNastaveni("offline", value);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(Languages.of(context)!.skipWeekend),
|
|
|
|
Switch(
|
|
|
|
value: _preskakovatVikend,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_preskakovatVikend = value;
|
|
|
|
zmenitNastaveni("skip", value);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-05-09 16:55:20 +02:00
|
|
|
)),
|
|
|
|
);
|
2022-05-02 12:07:47 +02:00
|
|
|
}
|
2022-05-20 08:03:53 +02:00
|
|
|
|
|
|
|
void cistit(bool value) async {
|
|
|
|
if (!value) {
|
|
|
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
|
|
|
for (var f in appDocDir.listSync()) {
|
|
|
|
// Vymažeme obsah
|
|
|
|
if (f.path.contains("jidelnicek")) {
|
|
|
|
f.deleteSync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-02 12:07:47 +02:00
|
|
|
}
|