缺少泛型函数“显示对话框”的类型参数。尝试添加显式类型,或从分析选项文件中删除隐式动态。
void displayDialog(BuildContext context) {
showDialog(
barrierDismissible: true,
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)),
elevation: 5,
title: const Text('Alert'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: const [
Text('Jhonny la gente estwa muy loca'),
SizedBox(
height: 10,
),
FlutterLogo(
size: 150,
)
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancelar'),
)
],
);
},
);
}发布于 2022-07-15 04:14:49
您的代码中没有问题。你可以试试这个。
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(home: PopUpTest());
}
}
class PopUpTest extends StatefulWidget {
const PopUpTest({Key? key}) : super(key: key);
@override
State<PopUpTest> createState() => _PopUpTestState();
}
class _PopUpTestState extends State<PopUpTest> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MaterialButton(
onPressed: () {
displayDialog(context);
},
child: const Text("Open pop up"),
color: Colors.blue,
)
],
),
),
);
}
void displayDialog(BuildContext context) {
showDialog(
barrierDismissible: true,
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)),
elevation: 5,
title: const Text('Alert'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: const [
Text('Jhonny la gente estwa muy loca'),
SizedBox(
height: 10,
),
FlutterLogo(
size: 150,
)
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancelar'),
)
],
);
},
);
}
}

https://stackoverflow.com/questions/72988937
复制相似问题