-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The two PDF-related menu items don't do anything yet, the other two sharing options are already operational. TODO improve the icons and add tests
- Loading branch information
Showing
7 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:app4training/l10n/l10n.dart'; | ||
import 'package:app4training/routes/view_page.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// Share button in the top right corner of the main view. | ||
/// Opens a dropdown with several sharing options. | ||
/// Implemented with MenuAnchor+MenuItemButton | ||
/// (seems to be preferred over PopupMenuButton since Material 3) | ||
class ShareButton extends ConsumerWidget { | ||
const ShareButton({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final menuController = MenuController(); | ||
final viewPage = context.findAncestorWidgetOfExactType<ViewPage>()!; | ||
String currentPage = viewPage.page; | ||
String currentLang = viewPage.langCode; | ||
|
||
return MenuAnchor( | ||
controller: menuController, | ||
builder: | ||
(BuildContext context, MenuController controller, Widget? child) { | ||
return IconButton( | ||
onPressed: () { | ||
if (controller.isOpen) { | ||
controller.close(); | ||
} else { | ||
controller.open(); | ||
} | ||
}, | ||
icon: const Icon(Icons.share), | ||
tooltip: 'Share', | ||
); | ||
}, | ||
menuChildren: [ | ||
Padding( | ||
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0), | ||
child: Column( | ||
children: [ | ||
Column(children: [ | ||
ListTile( | ||
dense: true, | ||
title: Text(context.l10n.sharePdf), | ||
leading: const Icon(Icons.picture_as_pdf), | ||
onTap: () { | ||
menuController.close(); | ||
}, | ||
), | ||
ListTile( | ||
dense: true, | ||
title: Text(context.l10n.openPdf), | ||
leading: const Icon(Icons.picture_as_pdf_outlined), | ||
onTap: () { | ||
menuController.close(); | ||
}, | ||
), | ||
ListTile( | ||
dense: true, | ||
title: Text(context.l10n.openInBrowser), | ||
leading: const Icon(Icons.open_in_browser), | ||
onTap: () async { | ||
menuController.close(); | ||
unawaited(launchUrl(Uri.parse( | ||
'https://www.4training.net/$currentPage/$currentLang'))); | ||
}), | ||
ListTile( | ||
dense: true, | ||
title: Text(context.l10n.shareLink), | ||
leading: const Icon(Icons.content_copy), | ||
onTap: () { | ||
menuController.close(); | ||
Share.share( | ||
'https://www.4training.net/$currentPage/$currentLang'); | ||
}, | ||
), | ||
]) | ||
], | ||
)) | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters