lot of work on rfplus

This commit is contained in:
Kima 2024-02-28 22:37:19 +01:00
parent c22b3e0de6
commit fea4d24e07
2 changed files with 481 additions and 433 deletions

View File

@ -20,14 +20,39 @@ class PremiumAuth {
PremiumAuth({required SettingsProvider settings}) : _settings = settings; PremiumAuth({required SettingsProvider settings}) : _settings = settings;
// initAuth() {
// try {
// _sub ??= uriLinkStream.listen(
// (Uri? uri) {
// if (uri != null) {
// final accessToken = uri.queryParameters['access_token'];
// if (accessToken != null) {
// finishAuth(accessToken);
// }
// }
// },
// onError: (err) {
// log("ERROR: initAuth: $err");
// },
// );
// launchUrl(
// Uri.parse(FilcAPI.plusAuthLogin),
// mode: LaunchMode.externalApplication,
// );
// } catch (err, sta) {
// log("ERROR: initAuth: $err\n$sta");
// }
// }
initAuth() { initAuth() {
try { try {
_sub ??= uriLinkStream.listen( _sub ??= uriLinkStream.listen(
(Uri? uri) { (Uri? uri) {
if (uri != null) { if (uri != null) {
final accessToken = uri.queryParameters['access_token']; final sessionId = uri.queryParameters['session_id'];
if (accessToken != null) { if (sessionId != null) {
finishAuth(accessToken); finishAuth(sessionId);
} }
} }
}, },
@ -37,7 +62,7 @@ class PremiumAuth {
); );
launchUrl( launchUrl(
Uri.parse(FilcAPI.plusAuthLogin), Uri.parse("${FilcAPI.payment}/stripe-create-checkout?product=asdasd"),
mode: LaunchMode.externalApplication, mode: LaunchMode.externalApplication,
); );
} catch (err, sta) { } catch (err, sta) {
@ -45,14 +70,34 @@ class PremiumAuth {
} }
} }
Future<bool> finishAuth(String accessToken) async { // Future<bool> finishAuth(String accessToken) async {
// try {
// // final res = await http.get(Uri.parse(
// // "${FilcAPI.plusScopes}?access_token=${Uri.encodeComponent(accessToken)}"));
// // final scopes =
// // ((jsonDecode(res.body) as Map)["scopes"] as List).cast<String>();
// // log("[INFO] Premium auth finish: ${scopes.join(',')}");
// await _settings.update(premiumAccessToken: accessToken);
// final result = await refreshAuth();
// // if (Platform.isAndroid) updateWidget();
// return result;
// } catch (err, sta) {
// log("[ERROR] reFilc+ auth failed: $err\n$sta");
// }
// await _settings.update(premiumAccessToken: "", premiumScopes: []);
// // if (Platform.isAndroid) updateWidget();
// return false;
// }
Future<bool> finishAuth(String sessionId) async {
try { try {
// final res = await http.get(Uri.parse( // final res = await http.get(Uri.parse(
// "${FilcAPI.plusScopes}?access_token=${Uri.encodeComponent(accessToken)}")); // "${FilcAPI.plusScopes}?access_token=${Uri.encodeComponent(accessToken)}"));
// final scopes = // final scopes =
// ((jsonDecode(res.body) as Map)["scopes"] as List).cast<String>(); // ((jsonDecode(res.body) as Map)["scopes"] as List).cast<String>();
// log("[INFO] Premium auth finish: ${scopes.join(',')}"); // log("[INFO] Premium auth finish: ${scopes.join(',')}");
await _settings.update(premiumAccessToken: accessToken); await _settings.update(plusSessionId: sessionId);
final result = await refreshAuth(); final result = await refreshAuth();
// if (Platform.isAndroid) updateWidget(); // if (Platform.isAndroid) updateWidget();
return result; return result;
@ -60,7 +105,7 @@ class PremiumAuth {
log("[ERROR] reFilc+ auth failed: $err\n$sta"); log("[ERROR] reFilc+ auth failed: $err\n$sta");
} }
await _settings.update(premiumAccessToken: "", premiumScopes: []); await _settings.update(plusSessionId: "", premiumScopes: []);
// if (Platform.isAndroid) updateWidget(); // if (Platform.isAndroid) updateWidget();
return false; return false;
} }

View File

@ -1,449 +1,452 @@
import 'package:dropdown_button2/dropdown_button2.dart'; // import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:refilc/api/providers/database_provider.dart'; // import 'package:refilc/api/providers/database_provider.dart';
import 'package:refilc/api/providers/user_provider.dart'; // import 'package:refilc/api/providers/user_provider.dart';
import 'package:refilc/models/settings.dart'; // import 'package:refilc/models/settings.dart';
import 'package:refilc/theme/colors/colors.dart'; // import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc/utils/format.dart'; // import 'package:refilc/utils/format.dart';
import 'package:refilc_kreta_api/models/teacher.dart'; // import 'package:refilc_kreta_api/models/teacher.dart';
import 'package:refilc_kreta_api/providers/absence_provider.dart'; // import 'package:refilc_kreta_api/providers/absence_provider.dart';
import 'package:refilc_kreta_api/providers/grade_provider.dart'; // import 'package:refilc_kreta_api/providers/grade_provider.dart';
import 'package:refilc_kreta_api/providers/timetable_provider.dart'; // import 'package:refilc_kreta_api/providers/timetable_provider.dart';
import 'package:refilc_mobile_ui/common/panel/panel.dart'; // import 'package:refilc_mobile_ui/common/panel/panel.dart';
import 'package:refilc_mobile_ui/common/panel/panel_button.dart'; // import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
// import 'package:refilc_plus/models/premium_scopes.dart'; // // import 'package:refilc_plus/models/premium_scopes.dart';
// import 'package:refilc_plus/providers/premium_provider.dart'; // // import 'package:refilc_plus/providers/premium_provider.dart';
// import 'package:refilc_plus/ui/mobile/premium/upsell.dart'; // // import 'package:refilc_plus/ui/mobile/premium/upsell.dart';
import 'package:flutter/cupertino.dart'; // import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart'; // import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart'; // import 'package:provider/provider.dart';
import 'package:refilc_mobile_ui/screens/settings/modify_names.i18n.dart'; // import 'package:refilc_mobile_ui/screens/settings/modify_names.i18n.dart';
class MenuRenamedTeachers extends StatelessWidget { // class MenuRenamedTeachers extends StatelessWidget {
const MenuRenamedTeachers({Key? key, required this.settings}) // const MenuRenamedTeachers({Key? key, required this.settings})
: super(key: key); // : super(key: key);
final SettingsProvider settings; // final SettingsProvider settings;
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return PanelButton( // return PanelButton(
padding: const EdgeInsets.only(left: 14.0), // padding: const EdgeInsets.only(left: 14.0),
onPressed: () { // onPressed: () {
// if (!Provider.of<PremiumProvider>(context, listen: false) // // if (!Provider.of<PremiumProvider>(context, listen: false)
// .hasScope(PremiumScopes.renameTeachers)) { // // .hasScope(PremiumScopes.renameTeachers)) {
// PremiumLockedFeatureUpsell.show( // // PremiumLockedFeatureUpsell.show(
// context: context, feature: PremiumFeature.teacherrename); // // context: context, feature: PremiumFeature.teacherrename);
// return; // // return;
// } // // }
Navigator.of(context, rootNavigator: true).push( // Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute(builder: (context) => const ModifyTeacherNames()), // CupertinoPageRoute(builder: (context) => const ModifyTeacherNames()),
); // );
}, // },
title: Text( // title: Text(
"rename_teachers".i18n, // "rename_teachers".i18n,
style: TextStyle( // style: TextStyle(
color: AppColors.of(context) // color: AppColors.of(context)
.text // .text
.withOpacity(settings.renamedTeachersEnabled ? 1.0 : .5)), // .withOpacity(settings.renamedTeachersEnabled ? 1.0 : .5)),
), // ),
leading: settings.renamedTeachersEnabled // leading: settings.renamedTeachersEnabled
? const Icon(FeatherIcons.users) // ? const Icon(FeatherIcons.users)
: Icon(FeatherIcons.users, // : Icon(FeatherIcons.users,
color: AppColors.of(context).text.withOpacity(.25)), // color: AppColors.of(context).text.withOpacity(.25)),
trailingDivider: true, // trailingDivider: true,
trailing: Switch( // trailing: Switch(
onChanged: (v) async { // onChanged: (v) async {
// if (!Provider.of<PremiumProvider>(context, listen: false) // // if (!Provider.of<PremiumProvider>(context, listen: false)
// .hasScope(PremiumScopes.renameTeachers)) { // // .hasScope(PremiumScopes.renameTeachers)) {
// PremiumLockedFeatureUpsell.show( // // PremiumLockedFeatureUpsell.show(
// context: context, feature: PremiumFeature.teacherrename); // // context: context, feature: PremiumFeature.teacherrename);
// return; // // return;
// } // // }
settings.update(renamedTeachersEnabled: v); // settings.update(renamedTeachersEnabled: v);
await Provider.of<GradeProvider>(context, listen: false) // await Provider.of<GradeProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
await Provider.of<TimetableProvider>(context, listen: false) // await Provider.of<TimetableProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
await Provider.of<AbsenceProvider>(context, listen: false) // await Provider.of<AbsenceProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
}, // },
value: settings.renamedTeachersEnabled, // value: settings.renamedTeachersEnabled,
activeColor: Theme.of(context).colorScheme.secondary, // activeColor: Theme.of(context).colorScheme.secondary,
), // ),
); // );
} // }
} // }
class ModifyTeacherNames extends StatefulWidget { // class ModifyTeacherNames extends StatefulWidget {
const ModifyTeacherNames({Key? key}) : super(key: key); // const ModifyTeacherNames({Key? key}) : super(key: key);
@override // @override
State<ModifyTeacherNames> createState() => _ModifyTeacherNamesState(); // State<ModifyTeacherNames> createState() => _ModifyTeacherNamesState();
} // }
class _ModifyTeacherNamesState extends State<ModifyTeacherNames> { // class _ModifyTeacherNamesState extends State<ModifyTeacherNames> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); // final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final _teacherName = TextEditingController(); // final _teacherName = TextEditingController();
String? selectedTeacherId; // String? selectedTeacherId;
late List<Teacher> teachers; // late List<Teacher> teachers;
late UserProvider user; // late UserProvider user;
late DatabaseProvider dbProvider; // late DatabaseProvider dbProvider;
late SettingsProvider settings; // late SettingsProvider settings;
@override // @override
void initState() { // void initState() {
super.initState(); // super.initState();
teachers = (Provider.of<GradeProvider>(context, listen: false) // teachers = (Provider.of<GradeProvider>(context, listen: false)
.grades // .grades
.map((e) => e.teacher) // .map((e) => e.teacher)
.toSet() // .toSet()
.toList() // .toList()
..sort((a, b) => a.name.compareTo(b.name))); // ..sort((a, b) => a.name.compareTo(b.name)));
user = Provider.of<UserProvider>(context, listen: false); // user = Provider.of<UserProvider>(context, listen: false);
dbProvider = Provider.of<DatabaseProvider>(context, listen: false); // dbProvider = Provider.of<DatabaseProvider>(context, listen: false);
} // }
Future<Map<String, String>> fetchRenamedTeachers() async { // Future<Map<String, String>> fetchRenamedTeachers() async {
return await dbProvider.userQuery.renamedTeachers(userId: user.id!); // return await dbProvider.userQuery.renamedTeachers(userId: user.id!);
} // }
void showRenameDialog() { // void showRenameDialog() {
showDialog( // showDialog(
context: context, // context: context,
builder: (context) => StatefulBuilder(builder: (context, setS) { // builder: (context) => StatefulBuilder(builder: (context, setS) {
return AlertDialog( // return AlertDialog(
shape: const RoundedRectangleBorder( // shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(14.0))), // borderRadius: BorderRadius.all(Radius.circular(14.0))),
title: Text("rename_teacher".i18n), // title: Text("rename_teacher".i18n),
content: Column( // content: Column(
mainAxisSize: MainAxisSize.min, // mainAxisSize: MainAxisSize.min,
children: [ // children: [
DropdownButton2( // DropdownButton2(
items: teachers // items: teachers
.map((item) => DropdownMenuItem<String>( // .map((item) => DropdownMenuItem<String>(
value: item.id, // value: item.id,
child: Text( // child: Text(
item.name, // item.name,
style: TextStyle( // style: TextStyle(
fontSize: 14, // fontSize: 14,
fontWeight: FontWeight.bold, // fontWeight: FontWeight.bold,
color: AppColors.of(context).text, // color: AppColors.of(context).text,
), // ),
overflow: TextOverflow.ellipsis, // overflow: TextOverflow.ellipsis,
), // ),
)) // ))
.toList(), // .toList(),
onChanged: (String? v) async { // onChanged: (String? v) async {
final renamedSubs = await fetchRenamedTeachers(); // final renamedSubs = await fetchRenamedTeachers();
setS(() { // setS(() {
selectedTeacherId = v; // selectedTeacherId = v;
if (renamedSubs.containsKey(selectedTeacherId)) { // if (renamedSubs.containsKey(selectedTeacherId)) {
_teacherName.text = renamedSubs[selectedTeacherId]!; // _teacherName.text = renamedSubs[selectedTeacherId]!;
} else { // } else {
_teacherName.text = ""; // _teacherName.text = "";
} // }
}); // });
}, // },
iconSize: 14, // iconStyleData: IconStyleData(
iconEnabledColor: AppColors.of(context).text, // iconSize: 14,
iconDisabledColor: AppColors.of(context).text, // iconEnabledColor: AppColors.of(context).text,
underline: const SizedBox(), // iconDisabledColor: AppColors.of(context).text,
itemHeight: 40, // ),
itemPadding: const EdgeInsets.only(left: 14, right: 14), // underline: const SizedBox(),
buttonWidth: 50, // menuItemStyleData: MenuItemStyleData(height: 40,),
dropdownWidth: 300, // itemHeight: 40,
dropdownPadding: null, // itemPadding: const EdgeInsets.only(left: 14, right: 14),
buttonDecoration: BoxDecoration( // buttonWidth: 50,
borderRadius: BorderRadius.circular(8), // dropdownWidth: 300,
), // dropdownPadding: null,
dropdownDecoration: BoxDecoration( // buttonDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14), // borderRadius: BorderRadius.circular(8),
), // ),
dropdownElevation: 8, // dropdownDecoration: BoxDecoration(
scrollbarRadius: const Radius.circular(40), // borderRadius: BorderRadius.circular(14),
scrollbarThickness: 6, // ),
scrollbarAlwaysShow: true, // dropdownElevation: 8,
offset: const Offset(-10, -10), // scrollbarRadius: const Radius.circular(40),
buttonSplashColor: Colors.transparent, // scrollbarThickness: 6,
customButton: Container( // scrollbarAlwaysShow: true,
width: double.infinity, // offset: const Offset(-10, -10),
decoration: BoxDecoration( // buttonSplashColor: Colors.transparent,
border: Border.all(color: Colors.grey, width: 2), // customButton: Container(
borderRadius: BorderRadius.circular(12.0), // width: double.infinity,
), // decoration: BoxDecoration(
padding: const EdgeInsets.symmetric( // border: Border.all(color: Colors.grey, width: 2),
vertical: 12.0, horizontal: 8.0), // borderRadius: BorderRadius.circular(12.0),
child: Text( // ),
selectedTeacherId == null // padding: const EdgeInsets.symmetric(
? "select_teacher".i18n // vertical: 12.0, horizontal: 8.0),
: teachers // child: Text(
.firstWhere( // selectedTeacherId == null
(element) => element.id == selectedTeacherId, // ? "select_teacher".i18n
orElse: () => Teacher( // : teachers
id: 'noid', name: "select_teacher".i18n), // .firstWhere(
) // (element) => element.id == selectedTeacherId,
.name, // orElse: () => Teacher(
style: Theme.of(context).textTheme.titleSmall!.copyWith( // id: 'noid', name: "select_teacher".i18n),
fontWeight: FontWeight.w700, // )
color: AppColors.of(context).text.withOpacity(0.75)), // .name,
overflow: TextOverflow.ellipsis, // style: Theme.of(context).textTheme.titleSmall!.copyWith(
maxLines: 2, // fontWeight: FontWeight.w700,
textAlign: TextAlign.center, // color: AppColors.of(context).text.withOpacity(0.75)),
), // overflow: TextOverflow.ellipsis,
), // maxLines: 2,
), // textAlign: TextAlign.center,
const Padding( // ),
padding: EdgeInsets.symmetric(vertical: 8.0), // ),
child: Icon(FeatherIcons.arrowDown, size: 32), // ),
), // const Padding(
TextField( // padding: EdgeInsets.symmetric(vertical: 8.0),
controller: _teacherName, // child: Icon(FeatherIcons.arrowDown, size: 32),
decoration: InputDecoration( // ),
border: OutlineInputBorder( // TextField(
borderSide: // controller: _teacherName,
const BorderSide(color: Colors.grey, width: 1.5), // decoration: InputDecoration(
borderRadius: BorderRadius.circular(12.0), // border: OutlineInputBorder(
), // borderSide:
focusedBorder: OutlineInputBorder( // const BorderSide(color: Colors.grey, width: 1.5),
borderSide: // borderRadius: BorderRadius.circular(12.0),
const BorderSide(color: Colors.grey, width: 1.5), // ),
borderRadius: BorderRadius.circular(12.0), // focusedBorder: OutlineInputBorder(
), // borderSide:
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0), // const BorderSide(color: Colors.grey, width: 1.5),
hintText: "modified_name".i18n, // borderRadius: BorderRadius.circular(12.0),
suffixIcon: IconButton( // ),
icon: const Icon( // contentPadding: const EdgeInsets.symmetric(horizontal: 12.0),
FeatherIcons.x, // hintText: "modified_name".i18n,
color: Colors.grey, // suffixIcon: IconButton(
), // icon: const Icon(
onPressed: () { // FeatherIcons.x,
setState(() { // color: Colors.grey,
_teacherName.text = ""; // ),
}); // onPressed: () {
}, // setState(() {
), // _teacherName.text = "";
), // });
), // },
], // ),
), // ),
actions: [ // ),
TextButton( // ],
child: Text( // ),
"cancel".i18n, // actions: [
style: const TextStyle(fontWeight: FontWeight.w500), // TextButton(
), // child: Text(
onPressed: () { // "cancel".i18n,
Navigator.of(context).maybePop(); // style: const TextStyle(fontWeight: FontWeight.w500),
}, // ),
), // onPressed: () {
TextButton( // Navigator.of(context).maybePop();
child: Text( // },
"done".i18n, // ),
style: const TextStyle(fontWeight: FontWeight.w500), // TextButton(
), // child: Text(
onPressed: () async { // "done".i18n,
if (selectedTeacherId != null) { // style: const TextStyle(fontWeight: FontWeight.w500),
final renamedSubs = await fetchRenamedTeachers(); // ),
// onPressed: () async {
// if (selectedTeacherId != null) {
// final renamedSubs = await fetchRenamedTeachers();
renamedSubs[selectedTeacherId!] = _teacherName.text; // renamedSubs[selectedTeacherId!] = _teacherName.text;
await dbProvider.userStore // await dbProvider.userStore
.storeRenamedTeachers(renamedSubs, userId: user.id!); // .storeRenamedTeachers(renamedSubs, userId: user.id!);
await Provider.of<GradeProvider>(context, listen: false) // await Provider.of<GradeProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
await Provider.of<TimetableProvider>(context, listen: false) // await Provider.of<TimetableProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
await Provider.of<AbsenceProvider>(context, listen: false) // await Provider.of<AbsenceProvider>(context, listen: false)
.convertBySettings(); // .convertBySettings();
} // }
Navigator.of(context).pop(true); // Navigator.of(context).pop(true);
setState(() {}); // setState(() {});
}, // },
), // ),
], // ],
); // );
}), // }),
).then((val) { // ).then((val) {
_teacherName.text = ""; // _teacherName.text = "";
selectedTeacherId = null; // selectedTeacherId = null;
}); // });
} // }
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
settings = Provider.of<SettingsProvider>(context); // settings = Provider.of<SettingsProvider>(context);
return Scaffold( // return Scaffold(
key: _scaffoldKey, // key: _scaffoldKey,
appBar: AppBar( // appBar: AppBar(
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, // surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
leading: BackButton(color: AppColors.of(context).text), // leading: BackButton(color: AppColors.of(context).text),
title: Text( // title: Text(
"modify_teachers".i18n, // "modify_teachers".i18n,
style: TextStyle(color: AppColors.of(context).text), // style: TextStyle(color: AppColors.of(context).text),
), // ),
), // ),
body: Padding( // body: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), // padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: SingleChildScrollView( // child: SingleChildScrollView(
child: Column( // child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
// Panel( // // Panel(
// child: SwitchListTile( // // child: SwitchListTile(
// title: Text("italics_toggle".i18n), // // title: Text("italics_toggle".i18n),
// onChanged: (value) => // // onChanged: (value) =>
// settings.update(renamedTeachersItalics: value), // // settings.update(renamedTeachersItalics: value),
// value: settings.renamedTeachersItalics, // // value: settings.renamedTeachersItalics,
// ), // // ),
// ), // // ),
// const SizedBox( // // const SizedBox(
// height: 20, // // height: 20,
// ), // // ),
InkWell( // InkWell(
onTap: showRenameDialog, // onTap: showRenameDialog,
borderRadius: BorderRadius.circular(12.0), // borderRadius: BorderRadius.circular(12.0),
child: Container( // child: Container(
width: double.infinity, // width: double.infinity,
decoration: BoxDecoration( // decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 2), // border: Border.all(color: Colors.grey, width: 2),
borderRadius: BorderRadius.circular(12.0), // borderRadius: BorderRadius.circular(12.0),
), // ),
padding: const EdgeInsets.symmetric( // padding: const EdgeInsets.symmetric(
vertical: 18.0, horizontal: 12.0), // vertical: 18.0, horizontal: 12.0),
child: Center( // child: Center(
child: Text( // child: Text(
"rename_new_teacher".i18n, // "rename_new_teacher".i18n,
style: TextStyle( // style: TextStyle(
fontWeight: FontWeight.w600, // fontWeight: FontWeight.w600,
fontSize: 18, // fontSize: 18,
color: AppColors.of(context).text.withOpacity(.85), // color: AppColors.of(context).text.withOpacity(.85),
), // ),
), // ),
), // ),
), // ),
), // ),
const SizedBox( // const SizedBox(
height: 30, // height: 30,
), // ),
FutureBuilder<Map<String, String>>( // FutureBuilder<Map<String, String>>(
future: fetchRenamedTeachers(), // future: fetchRenamedTeachers(),
builder: (context, snapshot) { // builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data!.isEmpty) { // if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Container(); // return Container();
} // }
return Panel( // return Panel(
title: Text("renamed_teachers".i18n), // title: Text("renamed_teachers".i18n),
child: Column( // child: Column(
children: snapshot.data!.keys.map( // children: snapshot.data!.keys.map(
(key) { // (key) {
Teacher? teacher = teachers.firstWhere( // Teacher? teacher = teachers.firstWhere(
(element) => key == element.id, // (element) => key == element.id,
orElse: () => Teacher(id: 'noid', name: 'noname'), // orElse: () => Teacher(id: 'noid', name: 'noname'),
); // );
if (teacher.id == 'noid') { // if (teacher.id == 'noid') {
return const SizedBox( // return const SizedBox(
width: 0, // width: 0,
height: 0, // height: 0,
); // );
} // }
String renameTo = snapshot.data![key]!; // String renameTo = snapshot.data![key]!;
return RenamedTeacherItem( // return RenamedTeacherItem(
teacher: teacher, // teacher: teacher,
renamedTo: renameTo, // renamedTo: renameTo,
modifyCallback: () { // modifyCallback: () {
setState(() { // setState(() {
selectedTeacherId = teacher.id; // selectedTeacherId = teacher.id;
_teacherName.text = renameTo; // _teacherName.text = renameTo;
}); // });
showRenameDialog(); // showRenameDialog();
}, // },
removeCallback: () { // removeCallback: () {
setState(() { // setState(() {
Map<String, String> subs = // Map<String, String> subs =
Map.from(snapshot.data!); // Map.from(snapshot.data!);
subs.remove(key); // subs.remove(key);
dbProvider.userStore.storeRenamedTeachers( // dbProvider.userStore.storeRenamedTeachers(
subs, // subs,
userId: user.id!); // userId: user.id!);
}); // });
}, // },
); // );
}, // },
).toList(), // ).toList(),
), // ),
); // );
}, // },
), // ),
], // ],
), // ),
), // ),
)); // ));
} // }
} // }
class RenamedTeacherItem extends StatelessWidget { // class RenamedTeacherItem extends StatelessWidget {
const RenamedTeacherItem({ // const RenamedTeacherItem({
Key? key, // Key? key,
required this.teacher, // required this.teacher,
required this.renamedTo, // required this.renamedTo,
required this.modifyCallback, // required this.modifyCallback,
required this.removeCallback, // required this.removeCallback,
}) : super(key: key); // }) : super(key: key);
final Teacher teacher; // final Teacher teacher;
final String renamedTo; // final String renamedTo;
final void Function() modifyCallback; // final void Function() modifyCallback;
final void Function() removeCallback; // final void Function() removeCallback;
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return ListTile( // return ListTile(
minLeadingWidth: 32.0, // minLeadingWidth: 32.0,
dense: true, // dense: true,
contentPadding: // contentPadding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0), // const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
visualDensity: VisualDensity.compact, // visualDensity: VisualDensity.compact,
onTap: () {}, // onTap: () {},
leading: Icon(FeatherIcons.user, // leading: Icon(FeatherIcons.user,
color: AppColors.of(context).text.withOpacity(.75)), // color: AppColors.of(context).text.withOpacity(.75)),
title: InkWell( // title: InkWell(
onTap: modifyCallback, // onTap: modifyCallback,
child: Column( // child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
Text( // Text(
teacher.name.capital(), // teacher.name.capital(),
style: TextStyle( // style: TextStyle(
fontWeight: FontWeight.w500, // fontWeight: FontWeight.w500,
fontSize: 14, // fontSize: 14,
color: AppColors.of(context).text.withOpacity(.75)), // color: AppColors.of(context).text.withOpacity(.75)),
maxLines: 1, // maxLines: 1,
overflow: TextOverflow.ellipsis, // overflow: TextOverflow.ellipsis,
), // ),
Text( // Text(
renamedTo, // renamedTo,
style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 16), // style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 16),
maxLines: 2, // maxLines: 2,
overflow: TextOverflow.ellipsis, // overflow: TextOverflow.ellipsis,
), // ),
], // ],
), // ),
), // ),
trailing: InkWell( // trailing: InkWell(
onTap: removeCallback, // onTap: removeCallback,
child: Icon(FeatherIcons.trash, // child: Icon(FeatherIcons.trash,
color: AppColors.of(context).red.withOpacity(.75)), // color: AppColors.of(context).red.withOpacity(.75)),
), // ),
); // );
} // }
} // }