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 ba75ce8d6d ==1.0.0==
- removed obsolete deps
- fixed many issues
- improved features
- added:
  * favourites
  * account console
  * push notifications
  * background sync
  * improved settings
2021-12-19 22:20:56 +01:00

198 lines
8.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:meincantor/networking.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:meincantor/const.dart';
import 'package:webviewx/webviewx.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: 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(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) {
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();
}
},
),
),
Padding(
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
child: FutureBuilder(
future: getSettingsString("name"),
builder: (context, snapshot) {
if (snapshot.hasData) {
return TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name',
icon: Icon(MdiIcons.passport)),
readOnly: true,
controller: TextEditingController(
text: snapshot.data as String),
);
} else {
return (const Center(
child: CircularProgressIndicator()));
}
}),
),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
child: FutureBuilder(
future: getSettingsString("user"),
builder: (context, snapshot) {
if (snapshot.hasData) {
return TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Benutzername',
icon: Icon(MdiIcons.identifier)),
readOnly: true,
controller: TextEditingController(
text: snapshot.data as String),
);
} else {
return (const Center(
child: CircularProgressIndicator()));
}
}),
),
const Divider(),
Padding(
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
child: FutureBuilder(
future: getSettingsString("email"),
builder: (context, snapshot) {
if (snapshot.hasData) {
return TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'E-Mail-Adresse',
icon: Icon(Icons.email_outlined)),
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(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0)),
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) => const AccountConsole()),
);
},
),
],
)),
);
}));
}
}
class AccountConsole extends StatefulWidget {
const AccountConsole({Key? key}) : super(key: key);
@override
AccountConsoleState createState() => AccountConsoleState();
}
class AccountConsoleState extends State<AccountConsole> {
@override
Widget build(BuildContext context) {
return WebViewX(
height: MediaQuery.of(context).size.height,
initialContent: 'https://mein.cantorgymnasium.de/auth/realms/GCG.MeinCantor/account/',
initialSourceType: SourceType.url,
javascriptMode: JavascriptMode.unrestricted,
width: MediaQuery.of(context).size.width
);
}
}