main.dart
//main.dart
import 'package:flutter/material.dart';
import 'package:flutter01/views/Detail.dart';
import 'package:flutter01/views/Home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter",
routes: {
"detail":(context)=>MyDetail(),
"home":(context)=>MyHome()
},
initialRoute: "home",
//初始化路由
);
}
}
Home.dart
//Home.dart
import 'package:flutter/material.dart';
class MyHome extends StatefulWidget {
@override
_MyHomeState createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(child: Text("go-Detail"),onPressed: getDetail,)
],
),
);
}
getDetail(){
Navigator.pushNamed(context, "detail");
}
}
Detail.dart
//Detail.dart
import 'package:flutter/material.dart';
class MyDetail extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: Container(
child: Text("详情页"),
),
);
}
}