56 lines
1.7 KiB
Dart
56 lines
1.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/sessions/chat_adaptive.dart';
|
|
|
|
/// Selects a retained pane when the window cannot show every chat at once.
|
|
Future<void> showChatPanePicker(
|
|
BuildContext context, {
|
|
required List<({String id, String title})> panes,
|
|
required String? activeId,
|
|
required ValueChanged<String> onSelected,
|
|
String title = 'Open chats',
|
|
}) async {
|
|
final String? selected;
|
|
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
|
selected = await showCupertinoModalPopup<String>(
|
|
context: context,
|
|
builder: (context) => CupertinoActionSheet(
|
|
title: Text(title),
|
|
actions: [
|
|
for (final pane in panes)
|
|
CupertinoActionSheetAction(
|
|
isDefaultAction: pane.id == activeId,
|
|
onPressed: () => Navigator.pop(context, pane.id),
|
|
child: Text(pane.title),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
selected = await showDialog<String>(
|
|
context: context,
|
|
builder: (context) => SimpleDialog(
|
|
title: Text(title),
|
|
children: [
|
|
for (final pane in panes)
|
|
SimpleDialogOption(
|
|
onPressed: () => Navigator.pop(context, pane.id),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(pane.title)),
|
|
if (pane.id == activeId) const Icon(Icons.check),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
if (selected != null && context.mounted) onSelected(selected);
|
|
}
|