Skip to content

Commit

Permalink
feat: add dialog to confirm to change group (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrKacz authored Mar 5, 2023
1 parent 27edf11 commit 5c1eec7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions chat-application/lib/dialogs/change_group.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:awachat/store/memory.dart';
import 'package:flutter/material.dart';

Future<bool?> dialogChangeGroup(BuildContext context) => (showDialog<bool>(
barrierDismissible: true,
context: context,
builder: (BuildContext context) {
final String city = Memory().boxUser.get('group-city')!;
Widget contentChild =
const Text('''Tu vas quitter ce groupe et en chercher un nouveau.''');
if (city != 'Je ne trouve pas ma ville') {
contentChild = Text(
'''Tu vas quitter ce groupe et en chercher un nouveau à $city.''');
}
return AlertDialog(
content: SingleChildScrollView(child: contentChild),
actions: <Widget>[
TextButton(
onPressed: () => (Navigator.pop(context, false)),
child: const Text('Refuser')),
TextButton(
onPressed: () => (Navigator.pop(context, true)),
child: const Text('Accepter'))
]);
}));
12 changes: 11 additions & 1 deletion chat-application/lib/widgets/chat/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:awachat/dialogs/change_group.dart';
import 'package:awachat/dialogs/message_actions.dart';
import 'package:awachat/dialogs/user_actions.dart';
import 'package:awachat/helpers/decode_jwt.dart';
Expand Down Expand Up @@ -168,6 +169,14 @@ class _ChatHandlerState extends State<ChatHandler> with WidgetsBindingObserver {

// ===== ===== =====
// Helpers
Future<void> pressedChangeGroup() async {
final bool isConfirmed = (await dialogChangeGroup(context)) ?? false;

if (isConfirmed) {
await changeGroup();
}
}

Future<void> changeGroup() async {
await User().changeGroup();

Expand Down Expand Up @@ -316,7 +325,8 @@ class _ChatHandlerState extends State<ChatHandler> with WidgetsBindingObserver {
title: const UsersList(),
actions: <Widget>[
SwitchActionButton(
isChatting: status == Status.chatting, onPressed: changeGroup)
isChatting: status == Status.chatting,
onPressed: pressedChangeGroup)
]),
body: ChatPage(
status: status,
Expand Down

0 comments on commit 5c1eec7

Please sign in to comment.