Теперь у меня есть страница с состоянием под названием ListVessel. Эта страница содержит listTile из массива других судов.
Ниже приведен код этой страницы.
Код: Выделить всё
class ListVessel extends StatefulWidget {
final Function() notifyParent;
ListVessel({Key key, @required this.notifyParent}) : super(key: key);
@override
_ListVesselState createState() => _ListVesselState();
}
class _ListVesselState extends State {
@override
Widget build(BuildContext context) {
return ListView.separated(
separatorBuilder: (context, index) => Divider(color: Colors.blueGrey),
itemCount: otherVessels.length,
itemBuilder: (context, index) {
return ListTile(
title: Text("Name: "+otherVessels[index]["shipName"]),
onTap: () {
showDialog (
context: context,
builder: (_){
return otherTap(idx:index);
}
);
}
);
},
);
}
}
}
Ниже приведен код методаotherTap().
Код: Выделить всё
class otherTap extends StatefulWidget{
otherTap({Key key, @required this.idx}) : super(key: key);
final int idx;
@override
_otherTapState createState() => new _otherTapState();
}
class _otherTapState extends State{
@override
Widget build(BuildContext context){
_isDialogShowing = true;
return SimpleDialog(
title: Text(otherVessels[widget.idx]["shipName"]),
children: [
SimpleDialogOption(
child: Text('MMSI : ' + otherVessels[widget.idx]['MMSI']),
)
],
);
}
}
Теперь я хочу, чтобы showdialog (всплывающее окно) отображалось закрыть через 5 секунд.
Я использую Navigator.pop(), чтобы закрыть диалоговое окно в функции MyApp. Я поместил его в функцию setstate().
Код: Выделить всё
void main() {
runApp(
MyApp(storage: CounterStorage()),
);
}
class MyApp extends StatefulWidget {
MyApp({Key key, @required this.storage}) : super(key: key);
final CounterStorage storage;
@override
State createState() => new _MyAppState();
}
class _MyAppState extends State {
final appTitle = 'Testing applicatin';
void _update(BuildContext context) async {
await Future.delayed(Duration(milliseconds: 5000));
setState(() {
if(_isDialogShowing){
_isDialogShowing = false;
Navigator.pop(context);
//Navigator.of(context).pop();
}
});
}
@override
Widget build(BuildContext context) {
_update(context);
return new WillPopScope(
onWillPop: null,
child: new MaterialApp(
debugShowCheckedModeBanner: false,
title: appTitle,
home: MyHomePage(title: appTitle),
routes: {
Routes.home: (context) => MyHomePage(),
Routes.settings: (context) => SettingsPage(),
},
),
);
}
}
Может ли кто-нибудь помочь?
Подробнее здесь: https://stackoverflow.com/questions/593 ... in-flutter