Blue line at the end of the screen flutter - flutter

I'm creating a dashboard from flutter. in my code, I have used the singlechildscroll view and it's not working. and I'm getting a blue line at the end of the page before the bottom navigation bar. I think it's because the page is not scrollable. There's no error display in the console. how do I correct this? appreciate your help on this.
import 'package:flutter/material.dart';
import '../constants/colors.dart';
import '../widgets/bottomNavigation.dart';
class DashboardScreen extends StatefulWidget {
const DashboardScreen({Key? key}) : super(key: key);
#override
_DashboardScreenState createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
Padding(
padding: const EdgeInsets.only(right: 15),
child: Container(
width: 30,
child: Image.asset(
'assets/images/user.png',
),
),
),
],
backgroundColor: Colors.transparent,
elevation: 0.0,
iconTheme: IconThemeData(color: Colors.black),
),
drawer: Drawer(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 20, left: 20),
child: Text(
"Hi, NEO",
style: TextStyle(
fontSize: 25,
color: Colors.black,
fontWeight: FontWeight.bold,
//fontFamily: "Dubai"
),
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.deepPurple,
),
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue,
),
),
],
),
// SizedBox(
// height: 30,
// ),
Row(
children: [
Padding(
padding: const EdgeInsets.only(top: 30, left: 20),
child: Text(
"Your Leads",
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontWeight: FontWeight.bold,
//fontFamily: "Dubai"
),
),
),
],
),
SizedBox(
height:30 ,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.lightGreen,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
Expanded(child: Container(child: BottomNavigation())),
],
),
);
}
}
[![enter image description here][1]][1]
//bottomnavigation
import 'package:flutter/material.dart';
class BottomNavigation extends StatefulWidget {
const BottomNavigation({Key? key}) : super(key: key);
#override
State<BottomNavigation> createState() => _BottomNavigationState();
}
class _BottomNavigationState extends State<BottomNavigation> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}

Looking at the updated code, both classes return a Scaffold with an Appbar. Thus, the blue box you see at the bottom is the Appbar of the class _BottomNavigationState.
Please refer to the code below for a correct implementation of a BottomNavigationBar.
Explanation
Generally, if one wants to encapsulate a BottomNavigationBar in its own Widget, this Widget needs to return a BottomNavigationBar in its build() method and not a Scaffold.
But usually, a BottomNavigationBar is used as shown below, without using an extra Widget.
Code
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
#override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
#override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'HOME PAGE',
style: optionStyle,
),
Text(
'COURSE PAGE',
style: optionStyle,
),
Text(
'CONTACT GFG',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('GeeksForGeeks'),
backgroundColor: Colors.green,
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
// HERE ! bottomNavigationBar: MyBottomNavigatioBar(...)
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.bookmark),
title: Text('Courses'),
),
BottomNavigationBarItem(
icon: Icon(Icons.contact_mail),
title: Text('Mail'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}
Source
https://www.geeksforgeeks.org/bottomnavigationbar-widget-in-flutter/

Okay I try your code and this is the result, I dont have any blue line, In your case I think you can try 2 possible solutions.
First one is to wrap your column with a singleChildScrollView, but I think you´ll need 2 columns one for the singleChildScrollView and another for the bottomNavigationBar.
Something like this:
body: Column(
children: [
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 20, left: 20),
child: Text(
"Hi, NEO",
style: TextStyle(
fontSize: 25,
color: Colors.black,
fontWeight: FontWeight.bold,
//fontFamily: "Dubai"
),
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.deepPurple,
),
),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue,
),
),
],
),
// SizedBox(
// height: 30,
// ),
Row(
children: [
Padding(
padding: const EdgeInsets.only(top: 30, left: 20),
child: Text(
"Your Leads",
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontWeight: FontWeight.bold,
//fontFamily: "Dubai"
),
),
),
],
),
SizedBox(
height:30 ,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.lightGreen,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 75,
width: 350,
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(0, 1),
blurRadius: 5,
color: Colors.black.withOpacity(0.3),
),
],
),
)
],
),
],
),
),
Expanded(child: Container( BottomNavigation )),
],
),
The second one is that your BottomNavigation have the problem of the blue line, and I can't test it because I don't see your code.

Related

flutter: how to change tab color?

I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.
I want to make change color on tab click.I want to make change color on tab click.I want to make change color on tab click.I want to make change color on tab click.
this is code
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/category_page.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class EventTab extends StatefulWidget {
#override
_EventTabState createState() => _EventTabState();
}
class _EventTabState extends State<EventTab> {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_tabSection(context),
],
);
}
}
Widget _tabSection(BuildContext context) {
return DefaultTabController(
length: 4,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 0),
child: TabBar(
isScrollable: true,
labelColor: Colors.black,
indicatorColor: Colors.white,
tabs: [
Tab(
child: Container(
width: 66,
height: 32,
decoration: const BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'All',
style: GoogleFonts.poppins(
color: Color(0xffffffff),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 85,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Category',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 85,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Upcoming',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
Tab(
child: Container(
width: 66,
height: 32,
decoration: const BoxDecoration(
color: Color(0xffF1F2F6),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Center(
child: Text(
'Free',
style: GoogleFonts.poppins(
color: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * (50 / 100),
child: const TabBarView(
children: [
Activities(),
CategoryPage(),
Activities(),
Activities(),
],
),
),
],
),
),
),
);
}
this time I have clicked on category page but I want to change color
Please Refer Below Code:-
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:cwc/ui/Event/components/activities.dart';
import 'package:cwc/ui/Event/components/category_page.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class EventTab extends StatefulWidget {
#override
_EventTabState createState() => _EventTabState();
}
class _EventTabState extends State<EventTab>
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
TabController controller;
#override
void initState() {
// TODO: implement initState
super.initState();
controller = TabController(length: 4, vsync: this);
controller.addListener(_handleTabSelection);
WidgetsBinding.instance.addObserver(this);
}
#override
void dispose() {
// TODO: implement dispose
super.dispose();
WidgetsBinding.instance.removeObserver(this);
controller?.dispose();
}
void _handleTabSelection() {
setState(() {});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
_tabSection(context, controller),
],
);
}
}
Widget _tabSection(BuildContext context, TabController controller) {
return DefaultTabController(
length: 4,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 10, 14, 0),
child: TabBar(
controller: controller,
unselectedLabelColor: Colors.grey,
indicatorColor: Colors.white,
isScrollable: true,
tabs: [
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 0
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'All',
style: GoogleFonts.poppins(
color: controller.index == 0
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 1
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Category',
style: GoogleFonts.poppins(
color: controller.index == 1
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 85,
height: 32,
color: controller.index == 2
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Upcoming',
style: GoogleFonts.poppins(
color: controller.index == 2
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
Tab(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
width: 66,
height: 32,
color: controller.index == 3
? Color(0xff158998)
: Color(0xffF1F2F6),
// decoration: const BoxDecoration(
// color: Color(0xffF1F2F6),
// borderRadius: BorderRadius.all(Radius.circular(10)),
// ),
child: Center(
child: Text(
'Free',
style: GoogleFonts.poppins(
color: controller.index == 3
? Color(0xffffffff)
: Color(0xff8F9698),
fontSize: 12,
),
),
),
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * (50 / 100),
child: const TabBarView(
children: [
Activities(),
CategoryPage(),
Activities(),
Activities(),
],
),
),
],
),
),
),
);
}

Cant align widgets correctly in Flutter

I have the following code, but i cant figure out, how to align the username to the left (next to the image) and the class-text to the right of the row. MainAxisAlignment.spaceBetween doesnt do the trick. I tried several different alignments on all the rows and columns but nothing is working. the only way i would get space between the two texts is by adding padding to one of the texts but this is not what want because the usernames have different sizes and the class text wouldnt be alligned to the right.
Container(
width: 180,
decoration: BoxDecoration(
color: const Color(0xffe8d9c3),
border: Border.all(color: Colors.transparent),
borderRadius: const BorderRadius.all(
Radius.circular(4),
),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0, 1),
),
],
),
child: Row(
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://www.woolha.com/media/2020/03/eevee.png',
),
),
const SizedBox(
width: 5,
),
Column(
//mainAxisAlignment: MainAxisAlignment.spaceBetween,
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StreamBuilder<DocumentSnapshot>(
stream: userdoc.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
return Text(
"${snapshot.data?["username"]}",
style: const TextStyle(
fontSize: 10,
color: Colors.black,
),
);
},
),
const Text(
"Class 8",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
],
),
Stack(
clipBehavior: Clip.none,
children: const [
SizedBox(
width: 120,
height: 15,
child: LinearProgressIndicator(
value: 0.3,
backgroundColor: Color(0xff816840),
color: Color(0xffffc518),
),
),
Positioned(
right: 10,
top: 2,
child: Text(
"2918",
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
],
),
],
),
)
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: Container(
width: 180,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: const Color(0xffe8d9c3),
border: Border.all(color: Colors.transparent),
borderRadius: const BorderRadius.all(
Radius.circular(4),
),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0, 1),
),
],
),
child: Row(
// crossAxisAlignment: CrossAxisAlignment.center,
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://www.woolha.com/media/2020/03/eevee.png',
),
),
const SizedBox(
width: 5,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: const [
Text(
"username",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
Spacer(),
Text(
"Class 8",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
],
),
Stack(
clipBehavior: Clip.none,
children: const [
SizedBox(
height: 15,
child: LinearProgressIndicator(
value: 0.5,
backgroundColor: Color(0xff816840),
color: Color(0xffffc518),
),
),
Positioned(
right: 10,
top: 2,
child: Text(
"2918",
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
],
),
),
],
),
),
)),
);
}
}
you can use Spacer() widget between them

How to use Flutter AnimatedContainer with height matching child

Currently this code works to resize a container to toggle between different content, but it's not animating. I think that I need to provide a height property to make the animation work, and when I do provide a height to toggle between it does match, like this:
height: selected ? 400 : 100,
The container animates smoothly between the two states. However the height is no longer adaptive. So I try to supply a height using:
GlobalKey _key = GlobalKey();
_size = _key.currentContext.size;
height: _size.height,
But it gives me errors and I'm not sure how to fix it.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedContainer(
// height: _size.height,
// key: _key,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height:20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
),
),
],
),
),
],
)
);
}
}
I thing AnimatedContainer is not Appropriate for this situation. I think its better to use AnimatedCrossFade. The AnimatedContainer will automatically animate between the old and new values of properties when they change using the provided curve and duration.
following code is refactored for using AnimatedCrossFade:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedCrossFade(
duration: Duration(seconds: 1),
crossFadeState: selected
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding:
EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin:
EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(20.0),
color: Colors.white,
border:
Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding:
const EdgeInsets.all(
10.0)),
keyboardType:
TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding:
const EdgeInsets.all(10.0)),
keyboardType:
TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue,
width: 1,
style: BorderStyle.solid),
borderRadius:
BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(
0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
secondChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
],
),
),
),
),
),
),
],
),
),
],
));
}
}
You can use custom animation to do this, like this:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
bool selected = false;
GlobalKey _key1 = GlobalKey();
GlobalKey _key2 = GlobalKey();
AnimationController _controller;
Animation _animation;
bool foward = false;
#override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(seconds: 1));
}
#override
void dispose() {
_controller.dispose();
super.dispose();
}
#override
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_animation = Tween<double>(
begin: _key1.currentContext.size.height,
end: _key2.currentContext.size.height +
_key1.currentContext.size.height)
.chain(CurveTween(curve: Curves.fastOutSlowIn))
.animate(_controller);
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
children: [
Padding(
padding: EdgeInsets.all(5),
child: GestureDetector(
onTap: () {
if (foward) {
_controller.reverse();
} else {
_controller.forward();
}
foward = !foward;
},
child: (_animation == null)
? _buildWidget(_key1, _key2)
: AnimatedBuilder(
// curve: Curves.fastOutSlowIn,
animation: _controller,
builder: (context, child) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17.0),
child: Container(
height: _animation.value, child: child),
));
},
child: _buildWidget(_key1, _key2)),
),
),
],
)));
}
Widget _buildWidget(Key key1, Key key2) {
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Widget1(
key: _key1,
),
Widget2(
key: _key2,
),
],
),
);
}
}
class Widget1 extends StatefulWidget {
Widget1({Key key}) : super(key: key);
#override
_Widget1State createState() => _Widget1State();
}
class _Widget1State extends State<Widget1> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
]);
}
}
class Widget2 extends StatefulWidget {
Widget2({Key key}) : super(key: key);
#override
Widget2State createState() => Widget2State();
}
class Widget2State extends State<Widget2> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Container(
child: Column(children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
))
])
]))
]);
}
}

Custom Button in Flutter

What I am trying to achieve is below:
Should I be using Row with Icon and Text?
Here is my code and its output
RaisedButton(
elevation: 10,
onPressed: () {},
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 55,
color: Colors.deepPurple,
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
),
],
),
),
);
OUTPUT:
Any help would be appreciated.
Here you go
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(), //.copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
get borderRadius => BorderRadius.circular(8.0);
#override
Widget build(BuildContext context) {
return Center(
child: Material(
elevation: 10,
borderRadius: borderRadius,
child: InkWell(
onTap: () {},
child: Container(
padding: EdgeInsets.all(0.0),
height: 60.0,//MediaQuery.of(context).size.width * .08,
width: 220.0,//MediaQuery.of(context).size.width * .3,
decoration: BoxDecoration(
borderRadius: borderRadius,
),
child: Row(
children: <Widget>[
LayoutBuilder(builder: (context, constraints) {
print(constraints);
return Container(
height: constraints.maxHeight,
width: constraints.maxHeight,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: borderRadius,
),
child: Icon(
Icons.settings,
color: Colors.white,
),
);
}),
Expanded(
child: Text(
'Settings',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
),
),
),
],
),
),
),
),
);
}
}
John Joe's answer is correct. Here is another solution that does the same with plain Container widget. I am posting it here just in case someone interested.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: Colors.white),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: MyWidget(),
),
],
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
height: 48.0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0)
]),
child: Stack(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
child: Align(
alignment: Alignment.center,
child: Icon(Icons.settings))),
Expanded(
child: Center(
child: Text("Hellow world",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.black)),
)),
],
),
SizedBox.expand(
child: Material(
type: MaterialType.transparency,
child: InkWell(onTap: () {}),
),
),
],
),
),
);
}
}
See the live demo here.
You can use Column and Row.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
_firstWidget(),
SizedBox(height: 15),
_secondWidget(),
],
)),
);
}
Widget _firstWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
height: 55,
width: 30,
decoration: myBoxDecoration(),
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Programs & Services',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
Widget _secondWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
decoration: myBoxDecoration(),
height: 55,
width: 30,
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
BoxDecoration myBoxDecoration() {
return BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(5.0) // <--- border radius here
),
);
}
Output
Darish's answer seems to me the best, since the splash is displayed on top of everything and makes a very good visual effect.
Even so, since the answer is from so long ago, I wanted to put here the updated code to NullSafety and also correct some bugs and remove unnecessary things.
For the rest it is perfect.
Here my code:
class MyWidget extends StatelessWidget {
const MyWidget({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.0),
boxShadow: const [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0,
)
],
),
child: SizedBox(
height: 48,
child: Stack(
children: [
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Icon(Icons.settings, color: Colors.white),
),
),
const Expanded(
child: Center(
child: Text("Hellow world"),
),
),
],
),
Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(8.0),
),
),
],
),
),
);
}
}

How to make custom tabbar with gradient

How to make tab bar like below image in flutter?Is it possible to develop a Tabbar like below ?If not possible then what is the next better working solution?
Thank you for the support and i solved this issue my self without using any answers from stackoverflow
Try this way
I have created tab layout using ScrollablePositionedList
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
void main() => runApp(HomeScreen());
int currentTab = 0;
class HomeScreen extends StatefulWidget {
#override
_HomeScreenPage createState() => _HomeScreenPage();
}
class TabModel {
String text;
TabModel({this.text});
}
List<TabModel> _tabList = [
TabModel(text: "Android"),
TabModel(text: "IOS"),
TabModel(text: "Java"),
TabModel(text: "JavaScript"),
TabModel(text: "PHP"),
TabModel(text: "HTML"),
TabModel(text: "C++"),
];
class _HomeScreenPage extends State<HomeScreen>
with SingleTickerProviderStateMixin {
PageController _controller = PageController(initialPage: 0, keepPage: false);
final ItemScrollController itemScrollController = ItemScrollController();
final ItemPositionsListener itemPositionListener =
ItemPositionsListener.create();
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.purple,
brightness: Brightness.light,
accentColor: Colors.red),
darkTheme: ThemeData(
brightness: Brightness.dark,
),
home: Scaffold(
appBar: AppBar(
title: Text("Custom TabBar"),
),
body: Column(
children: <Widget>[
Container(
height: 60,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
border: Border.all(color: Colors.black, width: 1.0)),
child: ScrollablePositionedList.builder(
scrollDirection: Axis.horizontal,
itemCount: _tabList.length,
itemBuilder: (context, index) {
return Container(
decoration: BoxDecoration(
gradient: currentTab == index
? LinearGradient(
colors: [
Colors.redAccent,
Colors.redAccent[200],
Colors.redAccent[100]
],
)
: null,
borderRadius: BorderRadius.circular(13.0),
),
child: FlatButton(
color: Colors.transparent,
onPressed: () {
setState(() {
currentTab = index;
_controller.jumpToPage(currentTab);
});
},
child: Text(
_tabList[index].text,
),
),
);
},
itemScrollController: itemScrollController,
itemPositionsListener: itemPositionListener,
)),
Flexible(
child: Container(
child: PageView(
controller: _controller,
onPageChanged: (pageId) {
setState(() {
currentTab = pageId;
itemScrollController.scrollTo(
index: currentTab, duration: Duration(seconds: 1));
});
},
children: <Widget>[
Container(
color: Colors.pink,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.cyan,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.red,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.green,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.grey,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.purple,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.teal,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
],
),
)),
],
)));
}
}
You can find source code for this demo from my github account
OUTPUT
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(home: MainScreen()),
);
class MainScreen extends StatefulWidget {
_MainState createState() => _MainState();
}
class _MainState extends State<MainScreen> {
int viewChoice = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Toolbar Title',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold /*fontSize,etc*/),
),
actions: [
IconButton(
icon: Icon(Icons.account_circle),
onPressed: () {
//Todo when pressed
}),
]),
body: Container(
child: Column(mainAxisSize: MainAxisSize.min, children: [
SizedBox(
height: 200,
width: double.infinity,
child: Stack(children: [
Container(
padding: EdgeInsets.all(10.0),
alignment: Alignment.centerLeft,
color: Colors.yellow,
height: 100.0,
width: double.infinity,
child: Text('Tem',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20.0)), //Tem is in your ex pic
),
Positioned(
top: 75.0,
left: 40.0,
right: 40.0,
child: Container(
margin: EdgeInsets.only(left: 25.0, right: 25.0),
alignment: Alignment.topCenter,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
border: Border.all(color: Colors.black, width: 1.0)),
child: Row(mainAxisSize: MainAxisSize.min, children: [
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: viewChoice == 0
? LinearGradient(
colors: [Colors.orange, Colors.orangeAccent],
)
: null,
borderRadius: BorderRadius.circular(13.0),
border: viewChoice == 0
? Border.all(color: Colors.black, width: 1.0)
: null,
),
child: FlatButton(
color: Colors.transparent,
onPressed: () {
setState(() {
viewChoice = 0;
});
},
child: Text(
'All',
/*style as your requirement*/
),
),
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: viewChoice == 1
? LinearGradient(
colors: [Colors.orange, Colors.orangeAccent],
)
: null,
borderRadius: BorderRadius.circular(13.0),
border: viewChoice == 1
? Border.all(color: Colors.black, width: 1.0)
: null,
),
child: FlatButton(
onPressed: () {
setState(() {
viewChoice = 1;
});
},
child: Text(
'Favorites',
/*style as your requirement*/
),
),
),
),
]),
),
),
]),
),
viewChoice == 0
? ListView(shrinkWrap: true, children: [
//Content of All categories
])
: ListView(shrinkWrap: true, children: [
//Content of All categories
])
]),
),
);
}
}
TabBar without AppBar
Give a try to below code.
import 'package:flutter/material.dart';
import 'package:flutter_text_to_image/utils/app_colors.dart';
class TabBarWidget extends StatefulWidget {
final String firstTabTxt;
final String firstTabViewTxt;
final String secondTabTxt;
final String secondTabViewTxt;
const TabBarWidget({
super.key,
required this.firstTabTxt,
required this.secondTabTxt,
required this.firstTabViewTxt,
required this.secondTabViewTxt,
});
#override
State
<TabBarWidget>
createState() => _TabBarWidgetState();
}
class _TabBarWidgetState extends State
<TabBarWidget>
with SingleTickerProviderStateMixin {
TabController? _tabController;
#override
void initState() {
_tabController = TabController(length: 2, vsync: this);
super.initState();
}
#override
void dispose() {
_tabController?.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Container(
height: 100,
child: Column(
children: [
Container(
height: 35,
decoration: BoxDecoration(
border: Border.all(
color: AppColors.tabBorderColor,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
gradient: LinearGradient(
colors: [
AppColors.waterMelonColor,
AppColors.mangoColor,
AppColors.azureColor,
AppColors.sapphireColor,
],
begin: FractionalOffset(0.0, 0.0),
end: FractionalOffset(1.0, 0.0),
stops: [
0.1,
0.4,
0.6,
1.0,
],
tileMode: TileMode.clamp,
),
borderRadius: BorderRadius.circular(
2.0,
),
),
labelColor: AppColors.whiteColor,
unselectedLabelColor: AppColors.blackColor,
tabs: [
Tab(
text: widget.firstTabTxt,
),
Tab(
text: widget.secondTabTxt,
),
],
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: [
Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
widget.firstTabViewTxt,
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
widget.secondTabViewTxt,
),
],
),
),
],
),
),
],
),
);
}
}