feat: Add chat permissions settings
This commit is contained in:
parent
068cb85f90
commit
4c8744f027
7 changed files with 466 additions and 81 deletions
32
lib/components/dialogs/adaptive_flat_button.dart
Normal file
32
lib/components/dialogs/adaptive_flat_button.dart
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AdaptiveFlatButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color textColor;
|
||||
final Function onPressed;
|
||||
|
||||
const AdaptiveFlatButton({
|
||||
Key key,
|
||||
this.child,
|
||||
this.textColor,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
return CupertinoDialogAction(
|
||||
child: child,
|
||||
onPressed: onPressed,
|
||||
textStyle: textColor != null ? TextStyle(color: textColor) : null,
|
||||
);
|
||||
}
|
||||
return FlatButton(
|
||||
child: child,
|
||||
textColor: textColor,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../avatar.dart';
|
||||
import 'adaptive_flat_button.dart';
|
||||
import 'simple_dialogs.dart';
|
||||
import '../../utils/string_color.dart';
|
||||
|
||||
|
|
@ -121,14 +122,14 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
),
|
||||
);
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).submit),
|
||||
onPressed: () {
|
||||
input = textEditingController.text;
|
||||
checkInput();
|
||||
},
|
||||
));
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).skip),
|
||||
onPressed: () => widget.request.openSSSS(skip: true),
|
||||
));
|
||||
|
|
@ -140,11 +141,11 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
style: TextStyle(fontSize: 20)),
|
||||
margin: EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
);
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).accept),
|
||||
onPressed: () => widget.request.acceptVerification(),
|
||||
));
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).reject),
|
||||
onPressed: () {
|
||||
widget.request.rejectVerification().then((_) {
|
||||
|
|
@ -204,11 +205,11 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
);
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).theyMatch),
|
||||
onPressed: () => widget.request.acceptSas(),
|
||||
));
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
textColor: Colors.red,
|
||||
child: Text(L10n.of(context).theyDontMatch),
|
||||
onPressed: () => widget.request.rejectSas(),
|
||||
|
|
@ -244,7 +245,7 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
);
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
buttons.add(AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
));
|
||||
|
|
@ -359,32 +360,3 @@ class _Emoji extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AdaptiveFlatButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color textColor;
|
||||
final Function onPressed;
|
||||
|
||||
const _AdaptiveFlatButton({
|
||||
Key key,
|
||||
this.child,
|
||||
this.textColor,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
return CupertinoDialogAction(
|
||||
child: child,
|
||||
onPressed: onPressed,
|
||||
textStyle: textColor != null ? TextStyle(color: textColor) : null,
|
||||
);
|
||||
}
|
||||
return FlatButton(
|
||||
child: child,
|
||||
textColor: textColor,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
85
lib/components/dialogs/permission_slider_dialog.dart
Normal file
85
lib/components/dialogs/permission_slider_dialog.dart
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class PermissionSliderDialog extends StatefulWidget {
|
||||
const PermissionSliderDialog({Key key, this.initialPermission = 0})
|
||||
: super(key: key);
|
||||
|
||||
Future<int> show(BuildContext context) => PlatformInfos.isCupertinoStyle
|
||||
? showCupertinoDialog<int>(context: context, builder: (context) => this)
|
||||
: showDialog<int>(context: context, builder: (context) => this);
|
||||
|
||||
final int initialPermission;
|
||||
@override
|
||||
_PermissionSliderDialogState createState() => _PermissionSliderDialogState();
|
||||
}
|
||||
|
||||
class _PermissionSliderDialogState extends State<PermissionSliderDialog> {
|
||||
int _permission;
|
||||
@override
|
||||
void initState() {
|
||||
_permission = widget.initialPermission;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final slider = PlatformInfos.isCupertinoStyle
|
||||
? CupertinoSlider(
|
||||
value: _permission.toDouble(),
|
||||
onChanged: (d) => setState(() => _permission = d.round()),
|
||||
max: 100.0,
|
||||
min: 0.0,
|
||||
)
|
||||
: Slider(
|
||||
value: _permission.toDouble(),
|
||||
onChanged: (d) => setState(() => _permission = d.round()),
|
||||
max: 100.0,
|
||||
min: 0.0,
|
||||
);
|
||||
final title = Text(
|
||||
L10n.of(context).setPermissionsLevel,
|
||||
textAlign: TextAlign.center,
|
||||
);
|
||||
final content = Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Level: ' +
|
||||
(_permission == 100
|
||||
? '$_permission (${L10n.of(context).admin})'
|
||||
: _permission >= 50
|
||||
? '$_permission (${L10n.of(context).moderator})'
|
||||
: _permission.toString())),
|
||||
Container(
|
||||
height: 56,
|
||||
child: slider,
|
||||
),
|
||||
],
|
||||
);
|
||||
final buttons = [
|
||||
AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).cancel),
|
||||
onPressed: () => Navigator.of(context).pop<int>(null),
|
||||
),
|
||||
AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).confirm),
|
||||
onPressed: () => Navigator.of(context).pop<int>(_permission),
|
||||
),
|
||||
];
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
return CupertinoAlertDialog(
|
||||
title: title,
|
||||
content: content,
|
||||
actions: buttons,
|
||||
);
|
||||
}
|
||||
return AlertDialog(
|
||||
title: title,
|
||||
content: content,
|
||||
actions: buttons,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue