2022-01-28 18:21:20 +01:00
|
|
|
//@dart=2.12
|
|
|
|
|
2020-12-05 13:03:57 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2020-12-05 13:03:57 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
import 'package:fluffychat/widgets/adaptive_flat_button.dart';
|
|
|
|
|
2020-12-05 13:03:57 +01:00
|
|
|
class PermissionSliderDialog extends StatefulWidget {
|
2021-01-19 15:46:43 +01:00
|
|
|
const PermissionSliderDialog({
|
2022-01-28 18:21:20 +01:00
|
|
|
Key? key,
|
2021-01-19 15:46:43 +01:00
|
|
|
this.initialPermission = 0,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-01-28 18:21:20 +01:00
|
|
|
Future<int?> show(BuildContext context) => PlatformInfos.isCupertinoStyle
|
2021-02-24 12:17:23 +01:00
|
|
|
? showCupertinoDialog<int>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => this,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-02-24 12:17:23 +01:00
|
|
|
)
|
|
|
|
: showDialog<int>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => this,
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-02-24 12:17:23 +01:00
|
|
|
);
|
2020-12-05 13:03:57 +01:00
|
|
|
|
|
|
|
final int initialPermission;
|
|
|
|
@override
|
|
|
|
_PermissionSliderDialogState createState() => _PermissionSliderDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
|
2022-01-28 18:21:20 +01:00
|
|
|
late int _permission;
|
2020-12-05 13:03:57 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_permission = widget.initialPermission;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final title = Text(
|
2022-01-28 18:21:20 +01:00
|
|
|
L10n.of(context)!.setPermissionsLevel,
|
2020-12-05 13:03:57 +01:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
);
|
|
|
|
final content = Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text('Level: ' +
|
|
|
|
(_permission == 100
|
2022-01-28 18:21:20 +01:00
|
|
|
? '$_permission (${L10n.of(context)!.admin})'
|
2020-12-05 13:03:57 +01:00
|
|
|
: _permission >= 50
|
2022-01-28 18:21:20 +01:00
|
|
|
? '$_permission (${L10n.of(context)!.moderator})'
|
2020-12-05 13:03:57 +01:00
|
|
|
: _permission.toString())),
|
2021-10-14 18:09:30 +02:00
|
|
|
SizedBox(
|
2020-12-05 13:03:57 +01:00
|
|
|
height: 56,
|
2021-12-23 13:34:04 +01:00
|
|
|
child: Slider.adaptive(
|
|
|
|
value: _permission.toDouble(),
|
|
|
|
onChanged: (d) => setState(() => _permission = d.round()),
|
|
|
|
max: 100.0,
|
|
|
|
min: 0.0,
|
|
|
|
),
|
2020-12-05 13:03:57 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
final buttons = [
|
|
|
|
AdaptiveFlatButton(
|
2022-01-28 18:21:20 +01:00
|
|
|
label: L10n.of(context)!.cancel,
|
2021-02-24 12:17:23 +01:00
|
|
|
onPressed: () =>
|
|
|
|
Navigator.of(context, rootNavigator: false).pop<int>(null),
|
2020-12-05 13:03:57 +01:00
|
|
|
),
|
|
|
|
AdaptiveFlatButton(
|
2022-01-28 18:21:20 +01:00
|
|
|
label: L10n.of(context)!.confirm,
|
2021-02-24 12:17:23 +01:00
|
|
|
onPressed: () =>
|
|
|
|
Navigator.of(context, rootNavigator: false).pop<int>(_permission),
|
2020-12-05 13:03:57 +01:00
|
|
|
),
|
|
|
|
];
|
|
|
|
if (PlatformInfos.isCupertinoStyle) {
|
|
|
|
return CupertinoAlertDialog(
|
|
|
|
title: title,
|
|
|
|
content: content,
|
|
|
|
actions: buttons,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return AlertDialog(
|
|
|
|
title: title,
|
|
|
|
content: content,
|
|
|
|
actions: buttons,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|