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/user_settings.dart
Denys Konovalov e86c1bad1d = 0.8.0-dev =
- code cleanup
- caching
- black-/whitelist
- sz/news fixes
- added settings options
...
2021-12-13 13:39:06 +01:00

134 lines
4.6 KiB
Dart

import 'package:cyclop/cyclop.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:meincantor/Settings/Pages/plan_settings.dart';
import 'package:meincantor/networking.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:io' show Platform;
import '../../const.dart';
Future<String> getSettingsString(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? value = prefs.getString(key);
if (value == null || value.isEmpty) {
value = "";
}
return value;
}
class UserSettings extends StatelessWidget {
const UserSettings({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
//TextEditingController nameController = TextEditingController(text: "Denys Konovalov");
return Scaffold(
appBar: AppBar(
title: const Text("Benutzereinstellungen"),
centerTitle: true,
),
body: ListView(
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
child: FutureBuilder(
future: Future.sync(() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? user = prefs.getString("user");
if (user == null || user.isEmpty) {
user = "";
}
String? name = prefs.getString("name");
if (name == null || name.isEmpty) {
name = "";
}
Map data = {"user": user, "name": name };
return data;
}),
builder: (context, snapshot) {
if (snapshot.hasData) {
// .svg?text=${(snapshot.data! as Map)['name'][0]}
String url = "$avatarUrl/${(snapshot.data! as Map)['user']}";
return Container(
width: 120.0,
height: 120.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.scaleDown,
image: NetworkImage(url)
)
)
);
} else {
return const CircularProgressIndicator();
}
},
),
),
FutureBuilder(
future: getSettingsString("name"),
builder: (context, snapshot) {
if (snapshot.hasData) {
return TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name',
),
readOnly: true,
controller:
TextEditingController(text: snapshot.data as String),
);
} else {
return (const Center(child: CircularProgressIndicator()));
}
}),
Padding(
padding: const EdgeInsets.fromLTRB(5, 20, 5, 5),
child: buildClassesChooser()),
ListTile(
leading: const Icon(MdiIcons.accountSettingsOutline),
trailing: const Icon(Icons.link, size: 16),
title: const Text("Account-Konsole"),
subtitle: const Text("Konto-Einstellungen öffnen"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AccountConsole()),
);
},
),
],
)
);
}
}
class AccountConsole extends StatefulWidget {
@override
AccountConsoleState createState() => AccountConsoleState();
}
class AccountConsoleState extends State<AccountConsole> {
@override
void initState() {
super.initState();
// Enable virtual display.
if (Platform.isAndroid) WebView.platform = AndroidWebView();
}
@override
Widget build(BuildContext context) {
return const WebView(
initialUrl: 'https://mein.cantorgymnasium.de/auth/realms/GCG.MeinCantor/account/',
);
}
}