这里的任何人都知道Flutter / Dart
我有一个defaultLayout,看起来像这样
final title = Data.appTitle;
var pages = [HomeScreen(), SearchPage(), LivePage(), AccountPage()];
String _currentRoute;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(title),
),
body: childViewBody(), //each class that extends Default() can modify this method to change body
//...Other Layout. BotAppBar is a custom widget
bottomNavigationBar: BotAppBar(
onTap: (index) {
setState(() {
//HERE... How can I make that whenever the BotAppBarItems are selected,.. the body is updated
});
},
items: [
BotAppBarItem(iconData: Icons.home, tooltip: Data.homeTitle),
BotAppBarItem(iconData: Icons.search, tooltip: Data.searchTitle),
BotAppBarItem(iconData: Icons.near_me, tooltip: Data.liveTitle),
BotAppBarItem(iconData: Icons.account_circle, tooltip: Data.accountTitle),
],
),
);
}
//Child class will modify this area to update screen.
childViewBody() {
return Column(
children: <Widget>[
Text('Placeholder')
],
);
}
...这应该在扩展它的任何类上更新
例如
class HomePage extends Default {//...super}
class HomePageState extends DefaultState {
@override
String get title => Data.homeTitle; //updates title in parent class
childViewBody() {
return Column{
//Build HomeScreen Body here
}
}
}
那么我将如何修改Default类,以便无论何时选择BotAppBar,主体都会更新...即使当前加载的类是子类
答案 0 :(得分:0)
您可以使用HeroAnimations
在上一个窗口上方打开一个新窗口,因为这是SearchWindows应显示给用户的方式。
这里是tutorial来实现。
如果HeroAnimations
听起来有点太多,
方向:
Navigator.push
导航到第二个屏幕Navigator.pop
返回第一个屏幕示例
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstScreen(),
));
}
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: RaisedButton(
child: Text('Launch screen'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
),
),
);
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}