Flutter:前往新視窗並且返回

Image for post
Image for post
Image for post
Image for post

導航到新頁面並返回

在上面提供的參考資料連結中,兩個screen都寫在main.dart中

import 'package:flutter/material.dart';
import 'SecondScreen.dart';

void main() {
runApp(
new MaterialApp(
title: 'Navigation Basics',
home: new FirstScreen(),
));
}

class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
centerTitle:true,
title: new Text('First Screen'),
),
body: new Center(
child: new RaisedButton(
child: new Text('Launch new screen'),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => new SecondScreen()),
);
},
),
),
);
}
}
import 'package:flutter/material.dart';


class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Second Screen"),
centerTitle:true,
),
body: new Center(
child: Image.network('https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/homepage/header-illustration.png'),
),

);
}
}

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store