|
| 1 | +// 🐦 Twitter https://twitter.com/vandadnp |
| 2 | +// 🔵 LinkedIn https://linkedin.com/in/vandadnp |
| 3 | +// 🎥 YouTube https://youtube.com/c/vandadnp |
| 4 | +// 💙 Free Flutter Course https://linktr.ee/vandadnp |
| 5 | +// 📦 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY |
| 6 | +// 🔶 7+ Hours MobX Course https://youtu.be/7Od55PBxYkI |
| 7 | +// 🦄 8+ Hours RxSwift Coursde https://youtu.be/xBFWMYmm9ro |
| 8 | +// 🤝 Want to support my work? https://buymeacoffee.com/vandad |
| 9 | + |
| 10 | +import 'package:flutter/material.dart'; |
| 11 | +import 'package:flutter/cupertino.dart'; |
| 12 | + |
| 13 | +void main() { |
| 14 | + runApp( |
| 15 | + const App(), |
| 16 | + ); |
| 17 | +} |
| 18 | + |
| 19 | +class App extends StatelessWidget { |
| 20 | + const App({ |
| 21 | + Key? key, |
| 22 | + }) : super(key: key); |
| 23 | + |
| 24 | + @override |
| 25 | + Widget build(BuildContext context) { |
| 26 | + return const CupertinoApp( |
| 27 | + debugShowCheckedModeBanner: false, |
| 28 | + home: HomePage(), |
| 29 | + ); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +class HomePage extends StatelessWidget { |
| 34 | + const HomePage({Key? key}) : super(key: key); |
| 35 | + |
| 36 | + @override |
| 37 | + Widget build(BuildContext context) { |
| 38 | + return CupertinoPageScaffold( |
| 39 | + navigationBar: const CupertinoNavigationBar( |
| 40 | + middle: Text('iOS Context Menu'), |
| 41 | + ), |
| 42 | + child: SafeArea( |
| 43 | + child: CupertinoContextMenu( |
| 44 | + previewBuilder: (_, __, child) => Rounded(child: child), |
| 45 | + actions: [ |
| 46 | + CupertinoContextMenuAction( |
| 47 | + child: const SaveRow(), |
| 48 | + onPressed: () { |
| 49 | + Navigator.of(context).pop(); |
| 50 | + }, |
| 51 | + ), |
| 52 | + CupertinoContextMenuAction( |
| 53 | + child: const ShareRow(), |
| 54 | + onPressed: () { |
| 55 | + Navigator.of(context).pop(); |
| 56 | + }, |
| 57 | + ), |
| 58 | + ], |
| 59 | + child: Image.network( |
| 60 | + 'https://bit.ly/3x7J5Qt', |
| 61 | + ), |
| 62 | + ), |
| 63 | + ), |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class Rounded extends StatelessWidget { |
| 69 | + final Widget child; |
| 70 | + const Rounded({ |
| 71 | + Key? key, |
| 72 | + required this.child, |
| 73 | + }) : super(key: key); |
| 74 | + |
| 75 | + @override |
| 76 | + Widget build(BuildContext context) { |
| 77 | + return Container( |
| 78 | + clipBehavior: Clip.antiAlias, |
| 79 | + decoration: BoxDecoration( |
| 80 | + borderRadius: BorderRadius.circular(20), |
| 81 | + boxShadow: [ |
| 82 | + BoxShadow( |
| 83 | + blurRadius: 2, |
| 84 | + color: Colors.black.withAlpha(40), |
| 85 | + spreadRadius: 2, |
| 86 | + ), |
| 87 | + ], |
| 88 | + ), |
| 89 | + child: child, |
| 90 | + ); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +class ShareRow extends StatelessWidget { |
| 95 | + const ShareRow({ |
| 96 | + Key? key, |
| 97 | + }) : super(key: key); |
| 98 | + |
| 99 | + @override |
| 100 | + Widget build(BuildContext context) { |
| 101 | + return Row( |
| 102 | + children: const [ |
| 103 | + Icon(Icons.save), |
| 104 | + SizedBox(width: 20.0), |
| 105 | + Text('Share'), |
| 106 | + ], |
| 107 | + ); |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +class SaveRow extends StatelessWidget { |
| 112 | + const SaveRow({ |
| 113 | + Key? key, |
| 114 | + }) : super(key: key); |
| 115 | + |
| 116 | + @override |
| 117 | + Widget build(BuildContext context) { |
| 118 | + return Row( |
| 119 | + children: const [ |
| 120 | + Icon(Icons.save), |
| 121 | + SizedBox(width: 20.0), |
| 122 | + Text('Save'), |
| 123 | + ], |
| 124 | + ); |
| 125 | + } |
| 126 | +} |
0 commit comments