How do I place the text to the left of the tabbar? - flutter

void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Viewer',
theme:
ThemeData(primaryColor: Colors.cyan, accentColor: Colors.tealAccent),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
margin: EdgeInsets.fromLTRB(100, 0, 0, 0),
child: Row(
children: <Widget>[
//Icon(Icons.settings)
Text('Blah'),
TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings))
],
),
],
),
),
preferredSize: Size.fromHeight(-8),
),
),
body: TabBarView(
children: [
Icon(Icons.search),
Icon(Icons.file_download),
Icon(Icons.settings),
],
),
),
),
);
}
}
I want to place the text on the blah part visible in the image.
Either way, I want to put a text in the left part of the tabbar.
I tried using row, but an overflow error occurred.
This occurred an error message.
How can I enter the text in that space?

Here is the code which will work for you
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hitomi Viewer',
theme:
ThemeData(primaryColor: Colors.cyan, accentColor: Colors.tealAccent),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: PreferredSize(
preferredSize: Size.fromHeight(-8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20),
child: Center(child: Text('Title'))),
SizedBox(
width: 50,
),
Flexible(
child: TabBar(
tabs: [
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings)),
],
),
),
],
),
)),
body: TabBarView(
children: [
Icon(Icons.search),
Icon(Icons.file_download),
Icon(Icons.settings),
],
),
),
),
);
}
}
OutPut:

I fixed it by fixing the code as follows:
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hitomi Viewer',
theme:
ThemeData(primaryColor: Colors.cyan, accentColor: Colors.tealAccent),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
margin: EdgeInsets.fromLTRB(100, 0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child: InkWell(
child: Text('Blah'),
),
margin: EdgeInsets.fromLTRB(10, 0, 80, 0),
),
TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings))
],
),
),
],
),
),
preferredSize: Size.fromHeight(-8),
),
),
body: TabBarView(
children: [
Icon(Icons.search),
Icon(Icons.file_download),
Icon(Icons.settings),
],
),
),
),
);
}
}

Since your tabs property is takinig a List<Widget>, use the Text widget in the tabs property instead.
Check the code below:
TabBar(
tabs: <Widget>[
// put your text widget here
Text('Blah'),
Tab(icon: Icon(Icons.search)),
Tab(icon: Icon(Icons.file_download)),
Tab(icon: Icon(Icons.settings))
],
),

Related

How can I resize the color picker widget

I use flutter_colorpicker: ^1.0.3 in my project.
I want the widget to be placed on the page without popping up the dialog.
It's difficult to resize the widget and color grid inside.
Like This:
I tried wrapping with container and SizedBox, but the result is not what I expected.
My expecting:
The grids are smaller.
The idea here is to provide a LayoutBuilder to BlockPicker.
I have done minimal code to showcase the UI.
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
),
useMaterial3: true,
),
home: const ColorPickerExample(),
);
}
}
class ColorPickerExample extends StatelessWidget {
const ColorPickerExample({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Edit'),
leading: IconButton(
onPressed: () {},
icon: const Icon(Icons.arrow_back),
),
),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
const CircleAvatar(
backgroundImage:
NetworkImage('https://i.pravatar.cc/300?img=30'),
radius: 60,
),
const SizedBox(
width: 30,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text('Herman Yun'),
Divider(),
Text('foobar#example.com')
],
),
],
),
const SizedBox(
height: 15,
),
Text(
'Select a color',
style: Theme.of(context).textTheme.headline5,
textAlign: TextAlign.start,
),
const SizedBox(
height: 5,
),
BlockPicker(
pickerColor: Colors.red,
onColorChanged: (_) {},
layoutBuilder: (context, colors, child) {
return GridView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 100,
childAspectRatio: 1.0,
crossAxisSpacing: 10,
mainAxisExtent: 100,
mainAxisSpacing: 10,
),
children: [for (Color color in colors) child(color)],
);
},
),
],
),
),
),
),
Container(
margin: const EdgeInsets.only(top: 25),
child: ElevatedButton(
onPressed: () {},
child: const SizedBox(
width: double.infinity,
child: Center(child: Text('Save')),
),
),
),
],
),
);
}
}

Flutter implement tab

I'm trying to make a page design like this:
But I'm having difficulties on implementing the tab bar. When the user click on 'Detail', then the detail view is showed under the tab bar and so on. Is there any widget to use?
try CupertinoSlidingSegmentedControl:
child: CupertinoSlidingSegmentedControl(
children: {
0: Text("FLIGHTS"),
1: Text("TRAINS"),
2: Text("HOTELS")
},
onValueChanged: (value)
{
selectedValue = value;
setState(() {
});
},
groupValue: selectedValue,
),
import 'package:flutter/material.dart';
class TabBarDemo extends StatelessWidget {
const TabBarDemo({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Tabs Demo'),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
height: 400,
child: const TabBarView(
children: [
Icon(Icons.directions_car),// create image widget here using listview builder
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
Container(
height: 80,
color: Colors.blue,
child: const TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
),
Container(
height: 400,
child: TabBarView(
children: [
Container(color: Colors.red,), // create data widgets here using listview builder
Container(color: Colors.green,),
Container(color: Colors.yellow,),
],
),
),
]
),
),
),
),
);
}
}

Navigator to the page from drawer get noSuchMethodError: the method '*' was called on null

The Drawer work perfectly, but after I add tab bar in the main page. The navigator from drawer to other page get error 'noSuchMethodError: the method '*' was called on null'. I mean, when click the listTile from drawer. It lead to that error.
This is my code
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: getTitleFontColor(),
centerTitle: true,
title: appBarTitle,
),
drawer: new Drawer(
child:
_drawerLeft(context),
),
body:
new DefaultTabController(
length: 3,
child: new Scaffold(
appBar: new AppBar(
actions: <Widget>[],
title:
TabBar(
isScrollable: true,
unselectedLabelColor: Colors.white.withOpacity(0.3),
indicatorColor: Colors.white,
tabs: [
Tab(
child: Text('A'),
),
Tab(
child: Text('B'),
),
Tab(
child: Text('C'),
),
]
),
),
body: TabBarView(
children: <Widget>[
Container(
//A,
),
Container(
child: ListView(
children:<Widget>[
Column(children: <Widget>[
// B,
],)
])
),
Container(
child: ListView(
children:<Widget>[
Column(children: <Widget>[
// C
],)
])
),
],
),
)
),
// ),
);
}
My _drawerLeft()
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: Icon(Icons.credit_card,color: getTitleFontColor()),
title: Text(
"A",
style: TextStyle(
color: getTitleFontColor(), fontSize: 16
)
),
onTap: () => {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => APage()),
),
},
),
])
Is it I use the navigator wrong? Can someone help please.

How to add a TabBar in AppBar in Flutter?

I have a AppBar as defined below. I want to add a TabBar below it. When i try to supply it in the bottom: property of the AppBar it throws a renderflex error:
This is my code:
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
body: Stack(
children: [
Positioned(
top: 15,
left: 15,
right: 15,
child: SafeArea(
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: AppBar(
title: Text('Hello', style: kTasksStyle),
centerTitle: true,
backgroundColor: kGreen,
),
),
),
),
],
)),
);
}
This is what the appBar looks like:
Probably you are trying to this
#override
Widget build(BuildContext context) {
final List<Tab> myTabs = <Tab>[
Tab(text: 'LEFT'),
Tab(text: 'RIGHT'),
];
return DefaultTabController(
length: 2,
child: SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Hello"),
centerTitle: true,
bottom: TabBar(
tabs: myTabs,
),
),
body: TabBarView(
children: myTabs.map((Tab tab) {
final String label = tab.text.toLowerCase();
return Center(
child: Text(
'This is the $label tab',
style: const TextStyle(fontSize: 36),
),
);
}).toList(),
),
),
),
);

how to create the tab bar without app bar in flutter?

I wish to add the tab app instead of app bar on my home screen. How to create it. Currently, my tab bar added at the bottom of app bar and I have removed the title and elevation. At the same time, I can't say appBar: null as I need some space on the top of the tab bar.
Widget HomeTap = new Scaffold(
appBar: new AppBar(
bottom: new TabBar(
indicatorColor: Colors.pinkAccent[100],
labelColor: Colors.pinkAccent[100],
indicatorWeight: 0.5,
unselectedLabelColor: Colors.grey[400],
tabs: [
new Tab(text: 'Album',),
new Tab(text: 'Artist'),
new Tab(text: 'Playlist'),
new Tab(text: 'Songs'),
new Tab(icon: new Icon(Icons.search))
]),
title: null,
elevation: 0.0,
),
body: new TabBarView(
children: [
new Center(
child: new AlbumWidget(),
),
new Container(),
new Container(),
new Container(),
new Container(),
],
),
);
Flutter works with composition. You can pretty much replace any widget with something else. They are not limited to one specific child.
So you can simply do
new Scaffold(
appBar: new TabBar(
...
),
...
)
The only requirement is for your widget to be of the right interface.
Scaffold requires as appBar a PreferredSizeWidget.
Fortunately, TabBar is already a PreferredSizeWidget by default. So no change needed
#override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text('Tabs Demo'),
),
body:
Column(
children: <Widget>[
TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
Expanded(
flex: 1,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
)
],
)
),
),
);
this worked for me
Tried flexibleSpace?
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
flexibleSpace: new Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TabBar(
tabs: [
Tab(text: "Pending"),
Tab(text: "Delivered"),
Tab(text: "Rejected"),
],
)
],
),
),
body: TabBarView(
children: [
PendingOrders(),
DeliveredOrders(),
RejectedOrders(),
],
),
),
);