// 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 . 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 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 { @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); } }