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/dev_settings.dart
Denys Konovalov 2dc41b7e24 - added license info
- fixed issues
2022-01-16 15:28:42 +01:00

145 lines
5.7 KiB
Dart

// GCG.MeinCantor - Die Schulplattform für Cantorianer.
// Copyright (C) 2021-2022 Georg-Cantor-Gymnasium Halle (Saale)
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:background_fetch/background_fetch.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:meincantor/background_fetch.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:meincantor/login.dart';
class DevSettings extends StatefulWidget {
const DevSettings({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _DevSettingsState();
}
class _DevSettingsState extends State<DevSettings> {
int _status = 0;
void _onClickStatus() async {
int status = await BackgroundFetch.status;
print('[BackgroundFetch] status: $status');
setState(() {
_status = status;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Entwickler-Einstellungen"),
centerTitle: true,
),
body: LayoutBuilder(builder: (context, constraints) {
double widgetWidth = constraints.maxWidth;
int factor;
if (widgetWidth <= 600) {
factor = 1;
} else if (widgetWidth <= 1400) {
factor = 2;
} else if (widgetWidth <= 2000) {
factor = 3;
} else {
factor = 1;
}
return Center(
heightFactor: 1,
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width / factor,
),
child: ListView(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: TextField(
decoration: const InputDecoration(
icon: Icon(MdiIcons.keyOutline),
border: OutlineInputBorder(),
labelText: 'MeinCantor API-Schlüssel',
),
onSubmitted: (String value) async {
SharedPreferences prefs =
await SharedPreferences.getInstance();
String apiKey = value;
await prefs.setString('api_key', apiKey);
final snackBar = SnackBar(
content: Text(
'Neuer API-Schlüssel gesetzt: $apiKey'));
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
})),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: OutlinedButton(
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Login()),
);
},
child: const Text("Benutzerdaten neu laden"),
)),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: OutlinedButton(
onPressed: () {
_onClickStatus();
},
child: const Text(
"Status der Hintergrundoperation anzeigen"),
)),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text(_status.toString())),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: OutlinedButton(
onPressed: () async {
await backgroundFetchTimetable();
},
child: const Text(
"Stundenplan im Hintergrund neu laden"),
)),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: OutlinedButton(
onPressed: () async {
await backgroundFetchArticles();
},
child: const Text(
"Schülerzeitung im Hintergrund neu laden"),
)),
],
)),
);
}));
}
}