made app modules movable in their order
This commit is contained in:
@ -3,76 +3,124 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:in_app_review/in_app_review.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../extensions/renderNotNull.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
|
||||
import '../../state/app/modules/app_modules.dart';
|
||||
import '../../storage/base/settingsProvider.dart';
|
||||
import '../../widget/centeredLeading.dart';
|
||||
import '../../widget/infoDialog.dart';
|
||||
import '../settings/defaultSettings.dart';
|
||||
import '../settings/settings.dart';
|
||||
import 'more/feedback/feedbackDialog.dart';
|
||||
import 'more/share/selectShareTypeDialog.dart';
|
||||
|
||||
class Overhang extends StatelessWidget {
|
||||
class Overhang extends StatefulWidget {
|
||||
const Overhang({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
State<Overhang> createState() => _OverhangState();
|
||||
}
|
||||
|
||||
class _OverhangState extends State<Overhang> {
|
||||
bool editMode = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Consumer<SettingsProvider>(builder: (context, settings, child) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Mehr'),
|
||||
actions: [
|
||||
IconButton(onPressed: () => pushScreen(context, screen: const Settings(), withNavBar: false), icon: const Icon(Icons.settings))
|
||||
if(editMode) IconButton(
|
||||
onPressed: settings.val().modulesSettings.toJson().toString() != DefaultSettings.get().modulesSettings.toJson().toString()
|
||||
? () => settings.val(write: true).modulesSettings = DefaultSettings.get().modulesSettings
|
||||
: null,
|
||||
icon: Icon(Icons.undo_outlined)
|
||||
),
|
||||
IconButton(onPressed: () => setState(() => editMode = !editMode), icon: Icon(Icons.edit_note_outlined), color: editMode ? Theme.of(context).primaryColor : null),
|
||||
IconButton(onPressed: editMode ? null : () => pushScreen(context, screen: const Settings(), withNavBar: false), icon: const Icon(Icons.settings)),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
AppModule.getModule(Modules.marianumMessage).toListTile(context),
|
||||
AppModule.getModule(Modules.roomPlan).toListTile(context),
|
||||
AppModule.getModule(Modules.gradeAveragesCalculator).toListTile(context),
|
||||
AppModule.getModule(Modules.holidays).toListTile(context),
|
||||
body: editMode ? _sorting() : _overhang(),
|
||||
));
|
||||
|
||||
const Divider(),
|
||||
Widget _sorting() => Consumer<SettingsProvider>(builder: (context, settings, child) {
|
||||
void changeVisibility(Modules module) {
|
||||
var hidden = settings.val(write: true).modulesSettings.hiddenModules;
|
||||
hidden.contains(module) ? hidden.remove(module) : (hidden.length < 3 ? hidden.add(module) : null);
|
||||
}
|
||||
|
||||
ListTile(
|
||||
return ReorderableListView(
|
||||
header: const Center(
|
||||
heightFactor: 2,
|
||||
child: Text('Halte und ziehe einen Eintrag, um ihn zu verschieben.\nEs können 3 Bereiche ausgeblendet werden.', textAlign: TextAlign.center)
|
||||
),
|
||||
children: AppModule.modules(context, showFiltered: true)
|
||||
.map((key, value) => MapEntry(key, value.toListTile(
|
||||
context,
|
||||
key: Key(key.name),
|
||||
isReorder: true,
|
||||
onVisibleChange: () => changeVisibility(key),
|
||||
isVisible: !settings.val().modulesSettings.hiddenModules.contains(key)
|
||||
)))
|
||||
.values
|
||||
.toList(),
|
||||
onReorder: (oldIndex, newIndex) {
|
||||
if (newIndex > oldIndex) newIndex -= 1;
|
||||
|
||||
var order = settings.val().modulesSettings.moduleOrder.toList();
|
||||
final movedModule = order.removeAt(oldIndex);
|
||||
order.insert(newIndex, movedModule);
|
||||
settings.val(write: true).modulesSettings.moduleOrder = order;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Widget _overhang() => ListView(
|
||||
children: [
|
||||
...AppModule.getOverhangModules(context).map((e) => e.toListTile(context)),
|
||||
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.share_outlined),
|
||||
title: const Text('Teile die App'),
|
||||
subtitle: const Text('Mit Freunden und deiner Klasse teilen'),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => showDialog(context: context, builder: (context) => const SelectShareTypeDialog())
|
||||
),
|
||||
FutureBuilder(
|
||||
future: InAppReview.instance.isAvailable(),
|
||||
builder: (context, snapshot) {
|
||||
if(!snapshot.hasData) return const SizedBox.shrink();
|
||||
),
|
||||
FutureBuilder(
|
||||
future: InAppReview.instance.isAvailable(),
|
||||
builder: (context, snapshot) {
|
||||
if(!snapshot.hasData) return const SizedBox.shrink();
|
||||
|
||||
String? getPlatformStoreName() {
|
||||
if(Platform.isAndroid) return 'Play store';
|
||||
if(Platform.isIOS) return 'App store';
|
||||
return null;
|
||||
}
|
||||
String? getPlatformStoreName() {
|
||||
if(Platform.isAndroid) return 'Play store';
|
||||
if(Platform.isIOS) return 'App store';
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.star_rate_outlined)),
|
||||
title: const Text('App bewerten'),
|
||||
subtitle: getPlatformStoreName().wrapNullable((data) => Text('Im $data')),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
InAppReview.instance.openStoreListing(appStoreId: '6458789560').then(
|
||||
(value) => InfoDialog.show(context, 'Vielen Dank!'),
|
||||
onError: (error) => InfoDialog.show(context, error.toString())
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.feedback_outlined)),
|
||||
title: const Text('Du hast eine Idee?'),
|
||||
subtitle: const Text('Fehler und Verbessungsvorschläge'),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => pushScreen(context, withNavBar: false, screen: const FeedbackDialog()),
|
||||
),
|
||||
],
|
||||
),
|
||||
return ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.star_rate_outlined)),
|
||||
title: const Text('App bewerten'),
|
||||
subtitle: getPlatformStoreName().wrapNullable((data) => Text('Im $data')),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
InAppReview.instance.openStoreListing(appStoreId: '6458789560').then(
|
||||
(value) => InfoDialog.show(context, 'Vielen Dank!'),
|
||||
onError: (error) => InfoDialog.show(context, error.toString())
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.feedback_outlined)),
|
||||
title: const Text('Du hast eine Idee?'),
|
||||
subtitle: const Text('Fehler und Verbessungsvorschläge'),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => pushScreen(context, withNavBar: false, screen: const FeedbackDialog()),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user