


Home.dart
import 'package:flutter/material.dart';
import 'package:untitled1/Pages/SearchPage.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
RaisedButton(
child: Text('跳转到搜索页面',style: TextStyle(
color: Colors.white
),),
onPressed: (){
Navigator.of(context).push(
MaterialPageRoute(
builder: (context)=>SearchPage(title: '搜索传值',)
)
);
},
color: Theme.of(context).accentColor,
textTheme: ButtonTextTheme.primary,//文字主题
)
],
),
);
}
}
SearchPage.dart
import 'package:flutter/material.dart';
class SearchPage extends StatelessWidget {
String title;
SearchPage({this.title='搜索'});
@override
Widget build(BuildContext context) {
return Scaffold(
//返回按钮
floatingActionButton: FloatingActionButton(
child: Text('返回',style: TextStyle(
color: Colors.white
),),
onPressed: (){
Navigator.of(context).pop();
},
),
appBar: AppBar(
title: Text(this.title,style: TextStyle(
color: Colors.amber
),),
),
body: Text('搜索页面'),
);
}
}
本文介绍了一个使用Flutter实现的简单应用,展示了如何在不同页面间进行导航,并通过参数传递实现页面间的通信。代码示例中,从主页跳转到搜索页,并可以携带标题参数。

5760

被折叠的 条评论
为什么被折叠?



