Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It won't desapear when opening new page #47

Closed
lucasagazzani opened this issue Mar 10, 2021 · 14 comments
Closed

It won't desapear when opening new page #47

lucasagazzani opened this issue Mar 10, 2021 · 14 comments

Comments

@lucasagazzani
Copy link

Hi,

so I am finding an issue in which when preasing navigation from the home page the bottom navigation bar won't desapare and I can't figure out why.

My code:

import` 'package:flutter/material.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:hopeapp/screens/give_page.dart';
import 'package:hopeapp/screens/home_screen.dart';
import 'package:hopeapp/screens/morepage.dart';
import 'package:flutter/services.dart';

void main() => runApp(
      new MaterialApp(
        darkTheme: ThemeData.light(),
        home: MyApp(),
      ),
    );

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MyAppState();
  }
}

class MyAppState extends State<MyApp> {
  int _selectedPage = 0;
  final _pageOptions = [
    HomeScreenTabBar(),
    GivePage(),
    MorePage(),
  ];

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.grey[900],
      statusBarIconBrightness: Brightness.light, // not working
      statusBarBrightness: Brightness.dark,
      // works
    ));
    return MaterialApp(
      title: 'Hope and Anchor App',
      theme: ThemeData(
        primarySwatch: Colors.yellow,
        primaryColor: Colors.yellow,
        brightness: Brightness.dark,
        accentColor: Colors.yellow,
      ),
      home: Scaffold(
        body: Center(
          child: _pageOptions.elementAt(_selectedPage),
        ),
        bottomNavigationBar: Container(
          decoration: BoxDecoration(color: Colors.grey[900], boxShadow: [
            BoxShadow(blurRadius: 20, color: Colors.black.withOpacity(0.0))
          ]),
          child: SafeArea(
            child: Padding(
              padding:
                  const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
              child: GNav(
                  gap: 1,
                  activeColor: Colors.yellow,
                  iconSize: 24,
                  padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8),
                  duration: Duration(milliseconds: 800),
                  tabBackgroundColor: Colors.black,
                  tabs: [
                    GButton(
                      icon: Icons.video_library,
                      iconColor: Colors.grey[500],
                      text: 'Home',
                    ),
                    GButton(
                      icon: Icons.favorite_border,
                      iconColor: Colors.grey[500],
                      text: 'Give',
                    ),
                    GButton(
                      icon: Icons.menu_rounded,
                      iconColor: Colors.grey[500],
                      text: 'More',
                    ),
                  ],
                  selectedIndex: _selectedPage,
                  onTabChange: (int index) {
                    setState(() {
                      _selectedPage = index;
                    });
                  }),
            ),
          ),
        ),
        backgroundColor: Colors.grey[900],
      ),
    );
  }
}
@sooxt98
Copy link
Owner

sooxt98 commented Mar 10, 2021

@lucasagazzani could you provide a video?

@lucasagazzani
Copy link
Author

@sooxt98
Copy link
Owner

sooxt98 commented Mar 10, 2021

@lucasagazzani this might be the nesting issue with your router, you need to use parent scaffold context to call Navigator.push

@lucasagazzani
Copy link
Author

This is how I have been calling them:
onTap: () { Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => LiveTab()), ); },

@sooxt98
Copy link
Owner

sooxt98 commented Mar 10, 2021

The problem here is you use two MaterialApp in your code, you need to remove one;

So change ur main to this

void main() => runApp(MyApp());

Then move your darkTheme: ThemeData.light() into the bottom MaterialApp

@lucasagazzani
Copy link
Author

I am sorry man but that hasn't fixed the issue

@sooxt98
Copy link
Owner

sooxt98 commented Mar 11, 2021

@lucasagazzani did u removed all MaterialApp widget? U could only use one MaterialApp in a whole flutter project; and also try to remove Navigator widget if any

@lucasagazzani
Copy link
Author

I have removed all material app theme and replaced it how you asked me

@lucasagazzani
Copy link
Author

I can't remove the MaterialApp in this case because the scaffold needs it

@sooxt98
Copy link
Owner

sooxt98 commented Mar 11, 2021

Scaffold won't be a problem when everything is wrap under one big MaterialApp widget during runApp

@lucasagazzani
Copy link
Author

ok, I thought you might be asking to remove it. Any other thought on what it could be?

@sooxt98
Copy link
Owner

sooxt98 commented Mar 11, 2021

@lucasagazzani the only reason that u get this issue is because you use more than one MaterialApp widget in your single project

@lucasagazzani
Copy link
Author

Ok, I found the page that had the extra MaterialApp now this issue is solved but do you know by any chance why themedata is not trasnfering to this page? Thank you for your help.

@sooxt98
Copy link
Owner

sooxt98 commented Mar 12, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants