以下代码为main.dart
:
import 'package:flutter/material.dart';
import 'landing page.dart';
void main() {
runApp(new MaterialApp(
home: LandingPages(),
));
}
这是我的目标网页课程:
import 'package:flutter/material.dart';
import 'package:listview/devices.dart';
import 'main.dart';
class LandingPages extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Is there anybody out there?',
home: new Scaffold(
body: new Stack(
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage( 'images/landing.png'),
fit: BoxFit.cover
),
),
),
new InkWell(
onTap: () =>print(Navigator.of(context).push(new MaterialPageRoute(builder:(BuildContext)=>MyApp()))),
)
],
)
),
);
}
}
第二页,我可以轻松地回到登录页面:
import 'package:flutter/material.dart';
import 'package:listview/devicepage.dart';
void main(){
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget{
@override
_State createState() =>new _State();
}
class _State extends State<MyApp>{
List<bool> _data =new List<bool>();
@override
void initState() {
setState(() {
for (int i=0;i<10;i++){
_data.add(false);
}
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar:new AppBar(
title: new Text("خانه هوشمند"),
),
body: new ListView.builder(
itemCount: _data.length,
itemBuilder: (BuildContext,int index){
return new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Image.asset(
'images/acc.png',
height: 100.0,
fit: BoxFit.contain,
),
],
),
const ListTile(
title: const Text('نام دستگاه',textAlign: TextAlign.left,),
subtitle: const Text('آخرین وضعیت موجود',textAlign: TextAlign.left,),
),
new ButtonTheme.bar( // make buttons use the appropriate styles for cards
child: new ButtonBar(
children: <Widget>[
new FlatButton(
child: const Text('بیشتر'),
onPressed: () { Navigator.push(context,MaterialPageRoute(builder: (context)=> DevicePage())); },
),
],
),
),
],
),
);
},
),
);
}
}
第二页上没有后退按钮,但是当我使用手机中的后退按钮时,它会转回来,任何人都可以打电话给我如何解决我的问题吗?
答案 0 :(得分:1)
在目标网页中使用Navigator.pushReplacement()
代替push
。