Created
October 3, 2022 11:29
-
-
Save cyb3rsalih/deb2205529a06b81a042ba5ed1ce8400 to your computer and use it in GitHub Desktop.
Modal Bottom Sheet
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
awesomeWidget(BuildContext context) { | |
var verticalGestures = Factory<VerticalDragGestureRecognizer>(() => VerticalDragGestureRecognizer()); | |
var gestureSet = {verticalGestures}; | |
final Completer<WebViewController> _controller = Completer<WebViewController>(); | |
Future<void> _loadHtmlString(Completer<WebViewController> controller, BuildContext context) async { | |
WebViewController _controller = await controller.future; | |
await _controller.loadHtmlString(webview_content); | |
} | |
return showModalBottomSheet<void>( | |
backgroundColor: Colors.transparent, | |
context: context, | |
builder: (BuildContext context) { | |
return Container( | |
decoration: const BoxDecoration( | |
color: Colors.amber, | |
borderRadius: BorderRadius.only( | |
topLeft: Radius.circular(50), | |
topRight: Radius.circular(50), | |
)), | |
height: MediaQuery.of(context).size.height * 0.8, | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
ElevatedButton( | |
child: const Text('Close BottomSheet'), | |
onPressed: () => Navigator.pop(context), | |
), | |
Expanded( | |
child: Padding( | |
padding: const EdgeInsets.all(12.0), | |
child: WebView( | |
initialUrl: 'https://flutter.dev', | |
javascriptMode: JavascriptMode.unrestricted, | |
onWebViewCreated: (WebViewController webViewController) async { | |
_controller.complete(webViewController); | |
_loadHtmlString(_controller, context); | |
}, | |
onProgress: (int progress) { | |
print('WebView is loading (progress : $progress%)'); | |
}, | |
navigationDelegate: (NavigationRequest request) { | |
if (request.url.startsWith('https://www.youtube.com/')) { | |
print('blocking navigation to $request}'); | |
return NavigationDecision.prevent; | |
} | |
print('allowing navigation to $request'); | |
return NavigationDecision.navigate; | |
}, | |
onPageStarted: (String url) { | |
print('Page started loading: $url'); | |
}, | |
onPageFinished: (String url) { | |
print('Page finished loading: $url'); | |
}, | |
gestureNavigationEnabled: true, | |
gestureRecognizers: gestureSet, | |
backgroundColor: const Color(0x00000000), | |
), | |
), | |
) | |
], | |
), | |
), | |
); | |
}, | |
isScrollControlled: true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment