refactor: Replace user bottom sheet with menu and small dialog
Signed-off-by: Krille <c.kussowski@famedly.com>
This commit is contained in:
parent
b6b1d6ddb1
commit
a12c48fae6
21 changed files with 734 additions and 851 deletions
|
|
@ -1,31 +1,72 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/dialog_text_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||
|
||||
Future<int?> showPermissionChooser(
|
||||
BuildContext context, {
|
||||
int currentLevel = 0,
|
||||
int maxLevel = 100,
|
||||
}) async {
|
||||
final customLevel = await showTextInputDialog(
|
||||
final controller = TextEditingController();
|
||||
final error = ValueNotifier<String?>(null);
|
||||
return await showAdaptiveDialog<int>(
|
||||
context: context,
|
||||
title: L10n.of(context).setPermissionsLevel,
|
||||
initialText: currentLevel.toString(),
|
||||
keyboardType: TextInputType.number,
|
||||
autocorrect: false,
|
||||
validator: (text) {
|
||||
if (text.isEmpty) {
|
||||
return L10n.of(context).pleaseEnterANumber;
|
||||
}
|
||||
final level = int.tryParse(text);
|
||||
if (level == null) {
|
||||
return L10n.of(context).pleaseEnterANumber;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
title: Text(L10n.of(context).chatPermissions),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12.0,
|
||||
children: [
|
||||
Text(L10n.of(context).setPermissionsLevelDescription),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: error,
|
||||
builder: (context, errorText, _) => DialogTextField(
|
||||
controller: controller,
|
||||
hintText: currentLevel.toString(),
|
||||
keyboardType: TextInputType.number,
|
||||
labelText: L10n.of(context).custom,
|
||||
errorText: errorText,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
AdaptiveDialogAction(
|
||||
bigButtons: true,
|
||||
onPressed: () {
|
||||
final level = int.tryParse(controller.text.trim());
|
||||
if (level == null) {
|
||||
error.value = L10n.of(context).pleaseEnterANumber;
|
||||
return;
|
||||
}
|
||||
if (level > maxLevel) {
|
||||
error.value = L10n.of(context).noPermission;
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop<int>(level);
|
||||
},
|
||||
child: Text(L10n.of(context).setCustomPermissionLevel),
|
||||
),
|
||||
if (maxLevel >= 100 && currentLevel != 100)
|
||||
AdaptiveDialogAction(
|
||||
bigButtons: true,
|
||||
onPressed: () => Navigator.of(context).pop<int>(100),
|
||||
child: Text(L10n.of(context).admin),
|
||||
),
|
||||
if (maxLevel >= 50 && currentLevel != 50)
|
||||
AdaptiveDialogAction(
|
||||
bigButtons: true,
|
||||
onPressed: () => Navigator.of(context).pop<int>(50),
|
||||
child: Text(L10n.of(context).moderator),
|
||||
),
|
||||
if (currentLevel != 0)
|
||||
AdaptiveDialogAction(
|
||||
bigButtons: true,
|
||||
onPressed: () => Navigator.of(context).pop<int>(0),
|
||||
child: Text(L10n.of(context).normalUser),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (customLevel == null) return null;
|
||||
return int.tryParse(customLevel);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue