This repository has been archived on 2024-07-21. You can view files and clone it, but cannot push or open issues or pull requests.
opencanteen/lib/okna/nastaveni.dart

97 lines
2.6 KiB
Dart
Raw Normal View History

import 'dart:io';
2022-05-02 12:07:47 +02:00
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
2022-05-09 16:55:20 +02:00
import 'package:shared_preferences/shared_preferences.dart';
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;
bool _preskakovatVikend = false;
2022-05-09 16:55:20 +02:00
void najitNastaveni() async {
var preferences = await SharedPreferences.getInstance();
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);
}
@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(
title: Text(Languages.of(context)!.settings),
2022-05-09 16:55:20 +02:00
),
body: Center(
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(() {
_ukladatOffline = value;
2022-05-20 08:03:53 +02:00
cistit(value);
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
}