Skip to content

Commit 4f05105

Browse files
committed
Use pull_down_button
1 parent a1c90ff commit 4f05105

File tree

5 files changed

+15
-111
lines changed

5 files changed

+15
-111
lines changed

examples/flyer_chat/lib/local.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:flyer_chat_reactions/flyer_chat_reactions.dart';
1515
import 'package:flyer_chat_system_message/flyer_chat_system_message.dart';
1616
import 'package:flyer_chat_text_message/flyer_chat_text_message.dart';
1717
import 'package:image_picker/image_picker.dart';
18+
import 'package:pull_down_button/pull_down_button.dart';
1819
import 'package:uuid/uuid.dart';
1920

2021
import 'create_message.dart';
@@ -363,24 +364,26 @@ class LocalState extends State<Local> {
363364
);
364365
}
365366

366-
List<MenuItem> _getMenuItems(Message message) {
367+
List<PullDownMenuEntry> _getMenuItems(Message message) {
367368
if (message.authorId == 'system') return [];
368369

369370
final items = [
370371
if (message is TextMessage)
371-
MenuItem(
372+
PullDownMenuItem(
372373
title: 'Copy',
373374
icon: CupertinoIcons.doc_on_doc,
374375
onTap: () {
375376
_copyMessage(message);
377+
Navigator.of(context).pop();
376378
},
377379
),
378-
MenuItem(
380+
PullDownMenuItem(
379381
title: 'Delete',
380382
icon: CupertinoIcons.delete,
381383
isDestructive: true,
382384
onTap: () {
383385
_removeItem(message);
386+
Navigator.of(context).pop();
384387
},
385388
),
386389
];

packages/flyer_chat_reactions/lib/flyer_chat_reactions.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export 'src/models/menu_item.dart';
21
export 'src/models/reaction.dart';
32
export 'src/widgets/flyer_chat_reactions_row.dart';
43
export 'src/widgets/reaction_tile.dart';

packages/flyer_chat_reactions/lib/src/models/menu_item.dart

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/flyer_chat_reactions/lib/src/widgets/reactions_dialog.dart

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import 'package:flutter_chat_core/flutter_chat_core.dart';
55
import 'package:flutter_chat_ui/flutter_chat_ui.dart'
66
show ChatProviders, buildMessageContent;
77
import 'package:provider/provider.dart';
8+
import 'package:pull_down_button/pull_down_button.dart'
9+
show PullDownMenuEntry, PullDownMenu;
810

911
import '../models/default_data.dart';
10-
import '../models/menu_item.dart';
1112
import '../utils/typedef.dart';
1213

1314
//// Theme values for [ReactionsDialogWidget].
@@ -55,7 +56,7 @@ class ReactionsDialogWidget extends StatefulWidget {
5556
final VoidCallback? onMoreReactionsTap;
5657

5758
/// The list of menu items to be displayed in the context menu
58-
final List<MenuItem>? menuItems;
59+
final List<PullDownMenuEntry>? menuItems;
5960

6061
/// The list of default reactions to be displayed
6162
final List<String>? reactions;
@@ -125,94 +126,10 @@ class _ReactionsDialogWidgetState extends State<ReactionsDialogWidget> {
125126
buildReactionsPicker(context, theme),
126127
const SizedBox(height: 10),
127128
widget.messageWidget,
128-
const SizedBox(height: 10),
129-
buildMenuItems(context, theme),
130-
],
131-
),
132-
),
133-
);
134-
}
135-
136-
Widget buildMenuItems(BuildContext context, _LocalTheme theme) {
137-
final destructiveColor = widget.menuItemDestructiveColor ?? Colors.red;
138-
return Material(
139-
color: Colors.transparent,
140-
child: Container(
141-
/// TODO: maybe use pixels, for desktop?
142-
width:
143-
MediaQuery.of(context).size.width *
144-
(widget.menuItemsWidthRatio ?? 0.45),
145-
decoration: BoxDecoration(
146-
color: widget.menuItemBackgroundColor ?? theme.surfaceContainer,
147-
borderRadius: theme.shape,
148-
),
149-
child: Column(
150-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
151-
mainAxisSize: MainAxisSize.min,
152-
children: [
153-
for (var item in widget.menuItems ?? const [])
154-
Column(
155-
children: [
156-
Padding(
157-
padding: const EdgeInsets.all(8),
158-
child: InkWell(
159-
onTap: () {
160-
setState(() {
161-
clickedContextMenuIndex = widget.menuItems?.indexOf(
162-
item,
163-
);
164-
});
165-
166-
Future.delayed(
167-
widget.menuItemTapAnimationDuration ??
168-
const Duration(milliseconds: 200),
169-
).whenComplete(() {
170-
if (context.mounted) {
171-
Navigator.of(context).pop();
172-
}
173-
item.onTap?.call();
174-
});
175-
},
176-
child: Row(
177-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
178-
children: [
179-
Text(
180-
item.title,
181-
style: TextStyle(
182-
color:
183-
item.isDestructive
184-
? destructiveColor
185-
: theme.onSurface,
186-
),
187-
),
188-
Pulse(
189-
infinite: false,
190-
duration:
191-
widget.menuItemTapAnimationDuration ??
192-
const Duration(milliseconds: 200),
193-
animate:
194-
clickedContextMenuIndex ==
195-
widget.menuItems?.indexOf(item),
196-
child: Icon(
197-
item.icon,
198-
color:
199-
item.isDestructive
200-
? destructiveColor
201-
: theme.onSurface,
202-
),
203-
),
204-
],
205-
),
206-
),
207-
),
208-
if (widget.menuItems?.last != item)
209-
Divider(
210-
color: widget.menuItemDividerColor ?? Colors.white,
211-
thickness: 0.5,
212-
height: 0.5,
213-
),
214-
],
215-
),
129+
if (widget.menuItems != null && widget.menuItems!.isNotEmpty) ...[
130+
const SizedBox(height: 10),
131+
PullDownMenu(items: widget.menuItems!),
132+
],
216133
],
217134
),
218135
),
@@ -333,7 +250,7 @@ void showReactionsDialog(
333250
required bool isSentByMe,
334251
required Function(String) onReactionTap,
335252
VoidCallback? onMoreReactionsTap,
336-
List<MenuItem>? menuItems,
253+
List<PullDownMenuEntry>? menuItems,
337254
List<String>? reactions,
338255
List<String>? userReactions,
339256
CrossAxisAlignment? widgetAlignment,

packages/flyer_chat_reactions/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
flutter_chat_core: ^2.7.0
1717
flutter_chat_ui: ^2.7.0
1818
provider: ^6.1.5
19+
pull_down_button: ^0.10.2
1920

2021
dev_dependencies:
2122
flutter_lints: ^6.0.0

0 commit comments

Comments
 (0)