I have a bottomNavigation Bar with a TabBarview as below:
#override
Widget build(BuildContext context) {
return new Scaffold(
//drawer: _drawer,
appBar: new AppBar(automaticallyImplyLeading: false,
title: new Text(_choice.title), actions: getAppBarActions(context)),
bottomNavigationBar: new Material(
color: CupertinoColors.lightBackgroundGray,
//color: c,
child: new Container(
height: 50.0,
child: new TabBar(
controller: controller,
//labelColor: Colors.grey,
tabs: mytablist,
labelStyle: new TextStyle(fontSize: 10.0),
labelColor: CupertinoColors.activeBlue,
unselectedLabelColor: CupertinoColors.inactiveGray,
isScrollable: true,
indicatorWeight: 1.0,
indicatorColor: CupertinoColors.activeBlue,
//indicatorPadding: new EdgeInsets.only(bottom: 5.0),
),
)),
body: new TabBarView(
controller: controller,
children: _tabWidgets(),
),
);
}
I have of courses pages that are navigated to, I also navigate to pages off the tabbarview that do not have the bottomnavigation, however I want to be able to navigate to one of the pages within the bottomnav, but when I do using something like this:
Navigator.of(context)..pushReplacementNamed(Chat.ChatServerPage.routeName);
It goes to the page but without the appbar or the bottomnavigationbar, anyone know how to accomplish this? I have tried all that I could find. Any help would be appreciated.
Check your widgets hierarchy. Usually MaterialApp widget is top level and it contains Navigator widget. That's why "navigation" replaces entire screen.
You could use different ways to implement this:
Each page has it's own Scaffold with AppBar and NavBar. Related question
It's possible to have multiple navigators. And separate Navigator could be added in Scaffold body. Related question
Related
im working on a UI app. manage to implement tabbar but got quite confused about a thin line above the tabbar. it's either a line or shadow, not sure. already run several code but doesn't manage to remove the line. the weird thing is, It seems to work the way i wanted on mobile ( chrome - mobile version / tablet ) but the line pop when opened in web version.
here is the problem ( that single line above the blue tabbar )
here is it, the same code when opened in mobile mode.
perfect clear without the line.
i try 2 version of code
DefaultTabController(
length: 2,
child: new Scaffold(
appBar: new PreferredSize(
preferredSize: Size.fromHeight(kToolbarHeight),
child: new Container(
color: Theme.of(context).primaryColor,
child: new SafeArea(
child: Column(
children: <Widget>[
new Expanded(child: new Container()),
new TabBar(
labelColor: Colors.white,
unselectedLabelColor: Colors.grey[700],
indicatorColor: Colors.white,
tabs: [
Tab(icon: Icon(Icons.chat)),
Tab(icon: Icon(Icons.filter_alt_outlined)),
],
),
],
),
),
),
),
body: TabBarView(
DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
flexibleSpace: SafeArea(
child: _tabBar,
),
backgroundColor: Theme.of(context).primaryColor,
elevation: 0,
),
body: TabBarView(
both of them works, but results are the same. that thin line above the tab bar persist. i just want to remove it. can anyone help ?
fullcode : github.com/CrazyBunnyz/Sociominer_V2/tree/error
change indicatorColor to transparent.
you have set indicator color to white.
replace that with indicatorColor: Colors.transparent,
It will work.
I solved my own question. lol. the problem lies in the header. instead of using container as the header, I just need to put the header ( container ) inside appbar first. i find it quite weird cause I don't put any decoration or style in the header. it has been solved anyway so no complain. thank you for everyone who takes their time to help me solve my problem
I've got a simple custom AppBar with the following code (I've taken out some code for simplification. It's not necessary for the question.):
class SimpleAppBarPageState extends StatelessWidget implements PreferredSizeWidget {
#override
Size get preferredSize => const Size.fromHeight(100);
#override
Widget build(BuildContext context) => DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
...
bottom: TabBar(
isScrollable: true,
indicatorColor: Colors.white,
indicatorWeight: 5,
tabs: [
Tab(child: Text('1',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20,
),
),
),
Tab(child: Text('2',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20,
),
),
)
],
),
elevation: 20,
titleSpacing: 20,
),
body: TabBarView(
children: [
buildPageOne(),
buildPageTwo()
],
),
),
);
Now I have two dart files of which one contains the code for Page one and the other file contains the code for page two.
Now I want page one to be open when Tab '1' is selected and page two should be open when Tab '2' is selected.
Therefor I thought of defining a new Widget which opens the corresponding page. Here are my thoughts:
Widget buildPageOne() {
Navigator.of(context)
.push(
MaterialPageRoute(
builder: (context) => PageOne()
),
);
}
I think this last code sample is complete useless, but it kind of shows my intention what should happen.
Can you guys help me out to solve this problem?
I'd be very happy about an answer!
Greetings
First of all don't use Navigator if you are using Tabs.
Second you need a TabController to handle your Tabs e.g. you can use the DefaultTabController. With TabBar you can set the text/icon of each tab below the Appbar. Within your TabBarView you set your Widgets you want to display. In your case omit the Navigator and just provide the Widgets you want to display in TabBarView
DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: 'Tabs',
bottom: TabBar(
tabs:[
Tab(icon: Icon(Icons.home)),
Tab(icon: Icon(Icons.settings)),
],
),
),
body: TabBarView(
children: [
Widget1(),
Widget2()
]
),
),
);
Don't use methods to navigator to new screen.
Create 2 separate stateless or statefull widgets: Widget1(), Widget2(),
And in childrens of TabBarView use these 2 widgets as children.
body: TabBarView(
children: [
Widget1(),
Widget2(),
],
),
Save them, do a hot restart
How to create vertical tab navigation for dashboard in flutter web and whats it the best way?
You can you a NavigationRail to get this look. It was added to flutter this year. It works almost like the bottom tab bar.
I believe you want something similiar to what is shown in the screenshot right?
If so, I would recommend you to use the Scaffold Widget and making use of the attributes appBar and drawer.
For further information about the Scaffold Widget please check this link.
Here a simple example:
In your main Widget modify the build function like this.
#override
Widget build(BuildContext context) {
GlobalKey<ScaffoldState> key = GlobalKey();
return Scaffold(
key: key,
drawer: Padding(
padding: const EdgeInsets.fromLTRB(0, 70, 0, 0),
child: Container(
color: Colors.red,
width: 300,
child: Column(children: [Text("1"), Text("2"), Text("3")])),
),
appBar: AppBar(
toolbarHeight: 70,
elevation: 5,
centerTitle: true,
backgroundColor: Colors.black,
leading: RawMaterialButton(
child: Icon(Icons.menu),
onPressed: () => key.currentState.openDrawer(),
),
title: Container(child: Text("Title Widget")),
),
body: Container(
child: Text("Main Widget"),
));
}
The result would look like this:
I am trying to build a custom scroll view which contains a sliver app bar to achieve something similar to what's shown here:
https://medium.com/#diegoveloper/flutter-collapsing-toolbar-sliver-app-bar-14b858e87abe
However I want to have the word Search and below it I want 3 IconButtons Evenly spaced, when the page (CustomScrollView) is scrolled, I want the 3 IconButtons to be pinned to the top of the SliverAppBar and the Search Text to disappear...
I Tried to achieve the above via the following code:
class SearchPage extends StatelessWidget {
const SearchPage();
#override
Widget build(BuildContext context) {
return CustomScrollView(slivers: <Widget>[
const SliverAppBar(
pinned: true,
expandedHeight: 250.0,
flexibleSpace: _buildSliverAppBarFlex(),
);
}
Widget _buildSliverAppBarFlex() {
return Container(
child: Column(
children: <Widget>[
Text("Search", style: TextStyle(fontSize: 24.0,
color: Colors.white,
fontWeight: FontWeight.bold)),
Row(children: <Widget>[
IconButton(icon: Icon(Icons.flight)),
IconButton(icon: Icon(Icons.hotel)),
IconButton(icon: Icon(Icons.drive_eta))
])
],
)
);
}
}
However I get a warning that flexibleSpace must take a const constructor widget and that the _buildSilverAppBarFlex Widget I've made is not - I cannot add const or final to it either... Any ideas how I can achieve what I want?
The warning comes because you are using const ahead of your SliverAppBar, remove this, and warning will be gone.
So, instead of this
const SliverAppBar(...)
Use this.
SliverAppBar(...)
If you want to use const there, make sure your FlexibleSpaceBar is also a const then.
I've been developing android apps for a while now and I'm currently porting an android app to flutter which I started not long ago. I have been able to make tabs scrollable in android but I'm finding it difficult to do that in flutter. I am able to create the tabs but they are about 7 and they exceed the screen width. Hence I want to make it scrollable to avoid that.
Below is what I did in the android app and I want to achieve something similar. Any help would be appreciated. Thanks.
You can use a DefaultTabController widget , also the Tab widget has a property called : isScrollable , set true and you will see.
This is a basic sample:
final List<Tab> myTabs = List.generate(
10,
(index) => Tab(text: 'TAB $index'),
);
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: myTabs.length,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
isScrollable: true,
tabs: myTabs,
),
),
body: TabBarView(
children: myTabs.map((Tab tab) {
return Center(child: Text(tab.text));
}).toList(),
),
),
);
}
You can find more info here: https://docs.flutter.io/flutter/material/DefaultTabController-class.html