[英]How to Use Function to Call it inside the Button
Currently, I use Navigation to bring up Dialog.目前,我使用导航来调出对话框。 But of course, the page will be changed, and the screen will only display the Dialog.
但是当然,页面会发生变化,屏幕上只会显示Dialog。 Like I've shown below:
就像我在下面展示的那样:
I want to fix it, so when the Dialog appear, the page behind it wouldn't disappear, like the picture below.我想修复它,所以当Dialog出现时,它后面的页面不会消失,如下图。
This is my code, with NavigationHelper, the screen will move to another screen to display Dialog, which I want to change that.这是我的代码,使用 NavigationHelper,屏幕将移动到另一个屏幕以显示对话框,我想更改它。
PopupMenuItem(
onTap: () {
GetIt.I<NavigationHelper>().go('/alert_delete_item');
},
value: 'Delete',
And this is a template to handle the Dialog, but I do not know how to use it.这是一个处理对话框的模板,但我不知道如何使用它。
Future<T?> showCustomDialog<T>(BuildContext context) {
return showDialog<T>(
context: context,
builder: (context) => Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: this,
),
);
}
Any tutorial how to use function?任何教程如何使用 function?
Should try this应该试试这个
import 'package:flutter/material.dart';
void main() {runApp(new MyApp());}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
home: Scaffold(
appBar: AppBar(title: Text('Dummy Screen')),
body: HomePage()
)
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {showAlertDialoge(context);},
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return ListTile(
title: Text("Heading ${index}" , style: Theme.of(context).textTheme.headline5,),
subtitle: Text("This is subtitle ${index}" ,),
);
},
),
);
}
void showAlertDialoge(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text("Dialog Box Occur in front of screen", style: TextStyle(fontSize: 16),),
)
);
}
}
OutPut: OutPut:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.