simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../api/marianumcloud/talk/actions/talk_actions.dart';
|
||||
import '../../../../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
||||
import '../../../../widget/async_action_button.dart';
|
||||
import '../../../../widget/confirm_dialog.dart';
|
||||
|
||||
class FavoriteToggleTile extends StatelessWidget {
|
||||
final bool isFavorite;
|
||||
final AsyncActionCallback onPressed;
|
||||
|
||||
const FavoriteToggleTile({
|
||||
required this.isFavorite,
|
||||
required this.onPressed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AsyncListTile(
|
||||
leading: Icon(isFavorite ? Icons.stars_outlined : Icons.star_outline),
|
||||
title: Text(
|
||||
isFavorite ? 'Von Favoriten entfernen' : 'Zu Favoriten hinzufügen',
|
||||
),
|
||||
onPressed: onPressed,
|
||||
);
|
||||
}
|
||||
|
||||
/// Asks for confirmation, leaves the room and refreshes the chat list.
|
||||
/// Resolves to true once the room was left.
|
||||
Future<bool> confirmLeaveRoom(BuildContext context, String token) async {
|
||||
final chatList = context.read<ChatListBloc>();
|
||||
final left = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => ConfirmDialog(
|
||||
title: 'Talk-Chat verlassen',
|
||||
content: 'Du benötigst ggf. eine Einladung um erneut beizutreten.',
|
||||
confirmButton: 'Verlassen',
|
||||
onConfirmAsync: () async {
|
||||
await LeaveRoom(token).run();
|
||||
unawaited(chatList.refresh());
|
||||
},
|
||||
),
|
||||
);
|
||||
return left ?? false;
|
||||
}
|
||||
Reference in New Issue
Block a user