Why does Navbar persist even after the page change?

Asked

Viewed 43 times

0

I made a Flutter screen using Cupertino, which by clicking on the "drive" field would open a "Drive" screen to choose the drive, but the Navigationbar that was used on one screen is being passed to another without at least passing it to the other page, and I’m not sure how to solve the problem;

Screenshot:

Image

 Widget build(BuildContext context) {
return PlatformTabScaffold(
  tabController: tabController,
  appBarBuilder: (_, index) => PlatformAppBar(
    android: (_) => MaterialAppBarData(
      centerTitle: true,
    ),
    ios: (_) => CupertinoNavigationBarData(
        backgroundColor: CupertinoColors.white,
        title: Text(
          titulo,
          style: TextStyle(color: CupertinoColors.black),
        )),
    title: (Text(titulo)),
  ),
  bodyBuilder: (context, index) => textPage(tabController.index(context)),
  itemChanged: (int a) {
    setState(() {
      titulo = pageName(a);
    });
  },
  iosTabs: (_) => CupertinoTabBarData(
    // Aba de Navegação do IOS
    items: <BottomNavigationBarItem>[
      BottomNavigationBarItem(
          icon: Icon(Icons.play_arrow), title: Text('Iniciar Dia')),
      BottomNavigationBarItem(
          icon: Icon(Icons.local_shipping), title: Text('Abastecer')),
      BottomNavigationBarItem(
          icon: Icon(Icons.stop), title: Text('Finalizar Dia')),
      BottomNavigationBarItem(
          icon: Icon(Icons.local_gas_station), title: Text('Tanque')),
      BottomNavigationBarItem(
          icon: Icon(Icons.equalizer), title: Text('Mais opções')),
    ],
    backgroundColor: CupertinoColors.lightBackgroundGray,
    activeColor: CupertinoColors.activeBlue,
    inactiveColor: CupertinoColors.inactiveGray,
  ),
  androidTabs: (_) => MaterialNavBarData(
    //Aba de  Navegação do Android
    type: BottomNavigationBarType.fixed,
    backgroundColor: Colors.orange[700],
    unselectedItemColor: Colors.black87,
    selectedItemColor: Colors.white70,
    showSelectedLabels: true,
    items: <BottomNavigationBarItem>[
      BottomNavigationBarItem(
          icon: Icon(Icons.play_arrow), title: Text('Iniciar Dia')),
      BottomNavigationBarItem(
          icon: Icon(Icons.local_shipping), title: Text('Abastecer')),
      BottomNavigationBarItem(
          icon: Icon(Icons.close), title: Text('Finalizar Dia')),
      BottomNavigationBarItem(
          icon: Icon(Icons.local_gas_station), title: Text('Tanque')),
      BottomNavigationBarItem(
          backgroundColor: Colors.orange,
          icon: Icon(Icons.equalizer),
          title: Text('Mais opções')),
    ],
  ),
);

}

When Clicking on "Drive" inserir a descrição da imagem aqui

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';

class UnidadeOpcoes extends StatefulWidget {
 @override
_UnidadeOpcoesState createState() => _UnidadeOpcoesState();
}

class _UnidadeOpcoesState extends State<UnidadeOpcoes> {
  var _currencies1 = ["one", "two", "three"];
  bool check = false;

 @override
 Widget build(BuildContext context) {
return PlatformScaffold(
  appBar: PlatformAppBar(
    title: Text("Unidade"),
    android: (_)   => MaterialAppBarData(
      automaticallyImplyLeading: true,

    ),
    ios: (_) => CupertinoNavigationBarData(
      trailing: CupertinoButton(
        padding: EdgeInsets.only(bottom: 0.0),
        child: Text("Salvar"),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      automaticallyImplyMiddle: true,
      leading: CupertinoButton(
        padding: EdgeInsets.only(bottom: 0.0),
        child: Text("Cancelar"),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
    ),
  ),
  body: Text("Teste"),
  ios: (_) => CupertinoPageScaffoldData(),
  android: (_) => MaterialScaffoldData(
    body: Container(
      color: Colors.white,
      child: ListView.builder(
        itemCount: _currencies1.length,
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            title: Text(
              _currencies1[index],
            ),
            leading: check == false
                ? Icon(Icons.check_box_outline_blank)
                : Icon(Icons.check_box, color: Colors.blueAccent),
            onTap: () {
              setState(() {
                check = !check;
              });
            },
          );
        },
      ),
    ),
  ),
);

} }

1 answer

0

This is usually due to the fact that CupertinoTabScaffold control the routes called from it.

To push a route above all tabs Instead of Inside the Currently Selected one (such as when Showing a dialog on top of this scaffold), use Navigator.of(rootNavigator: true) from Inside the Buildcontext of a Cupertinotabview.

Source: Cupertinotabcaffold

Then for your drive screen to be called above the Scaffold you need to do it this way:

Navigator.of(context, rootNavigator: true).push(...)
  • If you solved your problem, please mark as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.