【发布时间】:2020-03-06 08:03:56
【问题描述】:
每当用户单击特定列表项时,我使用下面的代码来获取警报
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
class RamList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return _myListView(context);
}
}
Widget _myListView(BuildContext context) {
final titles = [
'Part-1',
'part-2',
'part-3',
'part-4',
'part-5',
];
final numbers = [
'1 ',
'2 ',
'3 ',
'4 ',
'5 ',
];
functionOne() {
Navigator.push(
context, new MaterialPageRoute(builder: (context) => RamOne()));
}
functionTwo() {
Navigator.push(context, MaterialPageRoute(builder: (context) => RamTwo()));
}
functionThree() {
Navigator.push(
context, MaterialPageRoute(builder: (context) => RamThree()));
}
functionFour() {
Navigator.push(context, MaterialPageRoute(builder: (context) => RamFour()));
}
functionFive()=>_onAlertButtonPressed1;
final List<Function> onTaps = [
functionOne,
functionTwo,
functionThree,
functionFour,
functionFive,
];
return ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return Card(
elevation: 50,
child: InkWell(
child: Row(
children: <Widget>[
Container(
height: 100.0,
width:50.0,
decoration: BoxDecoration(
gradient:LinearGradientStyle.linearGradient(
orientation:LinearGradientStyle.ORIENTATION_HORIZONTAL,
gradientType: LinearGradientStyle.GRADIENT_TYPE_AMIN
)
),),
Container(
margin: EdgeInsets.all(10),
child: Text(
numbers[index],
)),
Flexible(child: Container(
margin: EdgeInsets.all(10),
child: GradientText((titles[index]),
gradient:gradient,
style:TextStyle(fontSize:20.0,fontWeight:FontWeight.bold, ),
),
))
],
),
onTap: () => onTaps[index](),
));
});
}
_onAlertButtonPressed1(context) {
Alert(
context: context,
type: AlertType.info,
title: "Coming soon",
desc: "This link will be available in future updates",
).show();
}
我尝试使用 rflutter alert 来显示警报。一切正常,没有任何错误。但是点击 destination listview 后没有出现警报.. 为什么这段代码不起作用。如果您有任何解决方案,请帮助我..
如果您需要更多信息,请发表评论。顺便说一下控制台消息工作正常。控制台框中没有错误消息。
【问题讨论】:
-
_onAlertButtonPressed1 函数在哪里调用?
-
见底部代码
-
看到函数的定义,但是没看到在哪里调用
-
如果您有任何解决方案,请回答
-
看起来你根本没有调用 _onAlertButtonPressed1 函数。我不确定,因为也许您只是没有显示所有代码。确保您确实调用了该函数。
标签: flutter dart flutter-alertdialog