【问题标题】:Bottom navigation bar transaction screens from first screen第一个屏幕的底部导航栏交易屏幕
【发布时间】:2019-02-13 07:11:16
【问题描述】:

我正在尝试从一个屏幕导航到另一个屏幕,如将在 android 部分解释。 为了实现底部导航栏,我使用了第一个片段中的片段,单击该按钮时我有一个按钮,我的第一个屏幕正在移动到导航栏的第二个选项卡,如下所示..

((NavigationActivity) getActivity()).navigation.setSelectedItemId(R.id.navigation_screen2); 

上面的行来自片段。 在 Flutter 中如何开发也是如此。提前致谢。

【问题讨论】:

标签: flutter flutter-layout flutter-test


【解决方案1】:

Home.dart 文件。你需要一个回调到onTabTapped 函数。

import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  final Function onTapped;  // CallBack Function

  Home({this.onTapped});

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        child: Column(
          children: <Widget>[
            Container(
              child: Column(
                children: <Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 16),
                        child: Text('WELCOME TO',
                            style: TextStyle(
                                fontSize: 24,
                                color: Color.fromRGBO(0, 0, 0, 1),
                                fontWeight: FontWeight.bold),
                            textAlign: TextAlign.center),
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        child: Text('Travelize',
                            style: TextStyle(
                              fontSize: 24,
                              color: Color.fromRGBO(35, 192, 103, 1),
                              fontWeight: FontWeight.bold,
                            ),
                            textAlign: TextAlign.center),
                      )
                    ],
                  ),
                  new Container(
                    margin: EdgeInsets.only(top: 80),
                    child: new MaterialButton(
                        padding: EdgeInsets.all(10.0),
                        child: Text("CHECK-IN"),
                        color: Color.fromRGBO(35, 192, 103, 1),
                        textColor: Colors.white,
                        onPressed: () {}),
                  ),
                  Center(child: _cardView()),
                  new Container(
                    margin: EdgeInsets.all(10),
                    child: new MaterialButton(
                        padding: EdgeInsets.all(10.0),
                        child: Text("MY VISIT"),
                        color: Color.fromRGBO(35, 192, 103, 1),
                        textColor: Colors.white,
                        onPressed: () {}),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _lineView() {
    return new Container(
      height: 1.5,
      margin: EdgeInsets.all(5),
      color: const Color.fromRGBO(195, 195, 195, 1),
    );
  }

  Widget _cardView() {
    return Card(
        margin: EdgeInsets.only(top: 40, right: 40, left: 40),
        child: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Container(
                    width: 50,
                    height: 50,
                    margin: EdgeInsets.only(top: 26),
                    child: Image.asset('assets/brandLogos/app_logo.png'))
              ],
            ),
            _lineView(),
            Container(
              padding: EdgeInsets.all(10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'You have',
                    style: TextStyle(fontSize: 16),
                  ),
                  Text(
                    ' 0 meetings',
                    style: TextStyle(
                        fontSize: 16, color: Color.fromRGBO(35, 192, 103, 1)),
                  ),
                  Text(
                    ' today',
                    style: TextStyle(fontSize: 16),
                  )
                ],
              ),
            ),
            _lineView(),
            new Container(
              margin: EdgeInsets.all(5),
              child: new MaterialButton(
                  child: Text("VIEW"),
                  color: Color.fromRGBO(35, 192, 103, 1),
                  textColor: Colors.white,
                  onPressed: () {
                    setState(() {
                      print(
                          '----dddddddddd------------clicked----------------');
                      widget.onTapped(1);  // Added this.

//                      dashBoardObj.DashboardScreen d =
//                          new dashBoardObj.DashboardScreen();
//                      d.createState().pageController.animateToPage(2,
//                          duration: Duration(milliseconds: 300),
//                          curve: Cubic(1, 1, 1, 1));
                    });
                  }),
            ),
          ],
        ));
  }
}

在你的DashboardScreen.dart

return Scaffold(
      appBar: AppBar(
        title: Text(appBarTitle),
      ),
//      body: _children[_currentIndex],
      body: pageView = new PageView(
        physics: new NeverScrollableScrollPhysics(),
        children: [
          Home(
            onTapped: onTabTapped,  // pass your function here
          ),
     ......

【讨论】:

    猜你喜欢
    • 2020-03-06
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多