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

94 lines
2.7 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) {
setState(() async {
_ukladatOffline = value;
if (!value) {
Directory appDocDir =
await getApplicationDocumentsDirectory();
for (var f in appDocDir.listSync()) {
// Vymažeme obsah
if (f.path.contains("jidelnicek")) {
f.deleteSync();
}
}
}
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
}
}