通过默认模板类更新正文

时间:2018-12-04 11:23:03

标签: dart flutter

这里的任何人都知道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
    }
}
}

Diagram.png

那么我将如何修改Default类,以便无论何时选择BotAppBar,主体都会更新...即使当前加载的类是子类

1 个答案:

答案 0 :(得分:0)

  

您可以使用HeroAnimations

在上一个窗口上方打开一个新窗口,因为这是SearchWindows应显示给用户的方式。

这里是tutorial来实现。

如果HeroAnimations 听起来有点太多

  

使用Navigation

方向:

  1. 创建两个屏幕
  2. 使用Navigator.push导航到第二个屏幕
  3. 使用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!'),
        ),
      ),
    );
  }
}

Here you go