kopia lustrzana https://gitlab.com/mysocialportal/relatica
				
				
				
			Add menu dialog on link opening button for external, copy url, and on posts "go to post"
							rodzic
							
								
									d16228223c
								
							
						
					
					
						commit
						99d94f3612
					
				|  | @ -5,6 +5,7 @@ import 'package:logging/logging.dart'; | |||
| import '../../globals.dart'; | ||||
| import '../../models/timeline_entry.dart'; | ||||
| import '../../services/timeline_manager.dart'; | ||||
| import '../../utils/clipboard_utils.dart'; | ||||
| import '../../utils/snackbar_builder.dart'; | ||||
| import '../../utils/url_opening_utils.dart'; | ||||
| 
 | ||||
|  | @ -122,18 +123,42 @@ class _InteractionsBarControlState extends State<InteractionsBarControl> { | |||
|   } | ||||
| 
 | ||||
|   Future<void> openAction(BuildContext context) async { | ||||
|     if (widget.openRemote) { | ||||
|       final openInBrowser = | ||||
|           await showYesNoDialog(context, 'Open in external browser?'); | ||||
|       if (openInBrowser == true && mounted) { | ||||
|     const goToPost = 'Go to Post'; | ||||
|     const copyUrl = 'Copy URL'; | ||||
|     const openExternal = 'Open In Browser'; | ||||
|     final options = [ | ||||
|       if (widget.showOpenControl && !widget.openRemote) goToPost, | ||||
|       openExternal, | ||||
|       copyUrl, | ||||
|       'Cancel' | ||||
|     ]; | ||||
|     final result = | ||||
|         await showChooseOptions(context, 'Would you like to', options); | ||||
| 
 | ||||
|     if (!mounted) { | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     switch (result) { | ||||
|       case goToPost: | ||||
|         context.push('/post/view/${widget.entry.id}/${widget.entry.id}'); | ||||
|         break; | ||||
|       case openExternal: | ||||
|         await openUrlStringInSystembrowser( | ||||
|           context, | ||||
|           widget.entry.externalLink, | ||||
|           'Post', | ||||
|         ); | ||||
|       } | ||||
|     } else { | ||||
|       context.push('/post/view/${widget.entry.id}/${widget.entry.id}'); | ||||
|         break; | ||||
|       case copyUrl: | ||||
|         await copyToClipboard( | ||||
|           context: context, | ||||
|           text: widget.entry.externalLink, | ||||
|           message: 'Post link copied to clipboard', | ||||
|         ); | ||||
|         break; | ||||
|       default: | ||||
|       //do nothing | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | @ -176,20 +201,19 @@ class _InteractionsBarControlState extends State<InteractionsBarControl> { | |||
|                 onPressed: | ||||
|                     isProcessing ? null : () async => await deleteEntry(), | ||||
|                 icon: Icon(Icons.delete)), | ||||
|           if (widget.showOpenControl) | ||||
|             Expanded( | ||||
|               child: Row( | ||||
|                 mainAxisAlignment: MainAxisAlignment.end, | ||||
|                 children: [ | ||||
|                   IconButton( | ||||
|                     onPressed: () async { | ||||
|                       await openAction(context); | ||||
|                     }, | ||||
|                     icon: const Icon(Icons.launch), | ||||
|                   ), | ||||
|                 ], | ||||
|               ), | ||||
|           Expanded( | ||||
|             child: Row( | ||||
|               mainAxisAlignment: MainAxisAlignment.end, | ||||
|               children: [ | ||||
|                 IconButton( | ||||
|                   onPressed: () async { | ||||
|                     await openAction(context); | ||||
|                   }, | ||||
|                   icon: const Icon(Icons.launch), | ||||
|                 ), | ||||
|               ], | ||||
|             ), | ||||
|           ), | ||||
|         ]), | ||||
|       ], | ||||
|     ); | ||||
|  |  | |||
|  | @ -60,3 +60,26 @@ Future<bool?> showYesNoDialog(BuildContext context, String caption) { | |||
|     }, | ||||
|   ); | ||||
| } | ||||
| 
 | ||||
| Future<String?> showChooseOptions( | ||||
|   BuildContext context, | ||||
|   String caption, | ||||
|   List<String> options, | ||||
| ) { | ||||
|   return showDialog<String?>( | ||||
|     context: context, | ||||
|     barrierDismissible: false, | ||||
|     builder: (BuildContext context) { | ||||
|       return AlertDialog( | ||||
|           title: Text(caption), | ||||
|           actions: options | ||||
|               .map((o) => ElevatedButton( | ||||
|                     child: Text(o), | ||||
|                     onPressed: () { | ||||
|                       Navigator.pop(context, o); // showDialog() returns true | ||||
|                     }, | ||||
|                   )) | ||||
|               .toList()); | ||||
|     }, | ||||
|   ); | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,15 @@ | |||
| import 'package:flutter/services.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
| 
 | ||||
| import 'snackbar_builder.dart'; | ||||
| 
 | ||||
| Future copyToClipboard({ | ||||
|   required BuildContext context, | ||||
|   required String text, | ||||
|   String message = 'Copied to clipboard', | ||||
| }) async { | ||||
|   await Clipboard.setData(ClipboardData(text: text)); | ||||
|   if (context.mounted) { | ||||
|     buildSnackbar(context, message); | ||||
|   } | ||||
| } | ||||
|  | @ -11,13 +11,19 @@ Future<bool> openUrlStringInSystembrowser( | |||
|     return false; | ||||
|   } | ||||
|   if (await canLaunchUrl(uri)) { | ||||
|     buildSnackbar( | ||||
|       context, | ||||
|       'Attempting to launch $label: $url', | ||||
|     ); | ||||
|     if (context.mounted) { | ||||
|       buildSnackbar( | ||||
|         context, | ||||
|         'Attempting to launch $label: $url', | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     await launchUrl(uri); | ||||
|   } else { | ||||
|     buildSnackbar(context, 'Unable to launch $label: $url'); | ||||
|     if (context.mounted) { | ||||
|       buildSnackbar(context, 'Unable to launch $label: $url'); | ||||
|     } | ||||
| 
 | ||||
|     return false; | ||||
|   } | ||||
|   return true; | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Hank Grabowski
						Hank Grabowski