flutter: how to change tab color? - flutter

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(),
],
),
),
],
),
),
),
);
}

Related

flutter issue: bottom overflowed by 57 pixels

Here my bottom preferredSize (preferredSize: Size.fromHeight(148.0)) in appBar.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
this is my code
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
import 'package:dropdown_button2/dropdown_button2.dart';
import 'dart:developer';
import '../../../APIMnager/APIManager.dart';
import '../../../APIMnager/preferences.dart';
import '../../../Constants/constants.dart';
import 'action_page.dart';
import 'holding_page.dart';
import 'overview_page.dart';
import 'report_page.dart';
class PMSListDataPage extends StatelessWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: ShowCaseWidget(
onStart: (index, key) {
log('onStart: $index, $key');
},
onComplete: (index, key) {
log('onComplete: $index, $key');
print("here me");
if (index == 0) {
Preferences.saveData("showCaseCount2", "2");
}
},
blurValue: 1,
builder: Builder(
builder: (context) => PMSListDataPage1(
panNum: panNum,
singlePMSData: singlePMSData,
allPMSListData: allPMSListData)),
autoPlayDelay: const Duration(seconds: 3),
),
);
}
}
class PMSListDataPage1 extends StatefulWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage1(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
_PMSListDataPage1State createState() => _PMSListDataPage1State();
}
class _PMSListDataPage1State extends State<PMSListDataPage1> {
var selectedValue;
ApiManager apiManager = ApiManager();
final GlobalKey _one = GlobalKey();
final GlobalKey _two = GlobalKey();
final GlobalKey _three = GlobalKey();
final scrollController = ScrollController();
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: DefaultTabController(
length: 4,
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back_ios_rounded),
onPressed: () {
Navigator.pop(context);
},
tooltip: '',
);
},
),
elevation: 0,
backgroundColor: skyBlue,
title: Text(
"PMS",
style: TextStyle(fontSize: tSize16),
),
actions: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IconButton(
icon: Image.asset(
"assets/phone_icon.png",
height: 25,
width: 25,
),
onPressed: () {
UrlLauncher.launch('tel:+91$UserRMNumber');
}))
],
)
],
bottom: PreferredSize(
preferredSize: Size.fromHeight(148.0),
child: Column(
children: [
Container(
color: skyBlue,
height: 90,
child:
nameView(widget.singlePMSData, widget.allPMSListData),
),
Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: TabBar(
overlayColor:
MaterialStateProperty.all(Colors.transparent),
indicatorColor: Colors.white,
unselectedLabelColor: lightBlue,
onTap: (v) {
searchHoldingsQuery.clear();
FocusScope.of(context).unfocus();
},
indicator: UnderlineTabIndicator(
borderSide: BorderSide(
color: Colors.white,
width: 3.2,
style: BorderStyle.solid),
insets: EdgeInsets.only(left: 30.0, right: 30)),
isScrollable: true,
labelColor: Colors.white,
tabs: [
Tab(
child: Text(
'OVERVIEW',
),
),
Tab(
child: Text(
'HOLDINGS',
),
),
Tab(
child: Text(
'REPORTS',
),
),
Tab(
child: Text(
'ACTIONS',
),
),
],
),
),
],
),
),
),
body:
TabBarView(physics: NeverScrollableScrollPhysics(), children: [
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: OverviewPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: HoldingPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ReportPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ActionPage(),
),
]),
)),
);
}
}
extension WidgetExtension on _PMSListDataPage1State {
nameView(singlePMSData, allPMSListData) {
return Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 5, bottom: 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
),
child: DropdownButtonHideUnderline(
child: DropdownButton2(
onMenuClose: () {},
onTap: () {},
isExpanded: true,
hint: Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
singlePMSData['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
'₹ ${singlePMSData["current_value"]}',
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
),
items: allPMSListData.map<DropdownMenuItem<Object>>((option) {
return DropdownMenuItem(
value: option,
child: Container(
width: double.infinity,
alignment: Alignment.centerLeft,
// padding: const EdgeInsets.fromLTRB(0,8.0,0,6.0),
child: Row(
children: [
SizedBox(
width: 10,
),
Text(
option["name"],
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
],
),
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: lightGreyColor, width: 1)))),
);
}).toList(),
selectedItemBuilder: (con) {
return allPMSListData.map<Widget>((item) {
return Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
"₹ ${item["current_value"]}",
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
);
}).toList();
},
value: selectedValue,
onChanged: (dynamic value) {
setState(() {
});
},
icon: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
size: 17,
),
),
iconOnClick: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_up,
color: Colors.white,
size: 17,
),
),
iconSize: 14,
buttonHeight: 70,
buttonPadding: const EdgeInsets.only(left: 14, right: 14),
buttonDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: lightBlue,
),
color: Colors.white,
),
buttonElevation: 1,
itemHeight: 44,
itemPadding: const EdgeInsets.only(left: 14, right: 14),
dropdownMaxHeight: 200,
dropdownPadding: null,
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
color: Colors.white,
),
dropdownElevation: 1,
scrollbarRadius: const Radius.circular(40),
scrollbarThickness: 3,
scrollbarAlwaysShow: false,
// offset: const Offset(-10, 0),
),
),
),
);
}
}

Blue line at the end of the screen 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.

Flutter : Radio button

i want to turn my three buttons to radio button , so When you click on any of them, the border color and background color are changed , like the one in the middle
my button code
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.white,
width: 1,
),
),
height: 65,
width: 350,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('1 WEEK' , style: TextStyle(
fontSize: 18,
color: Colors.white,
),),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text('2.99' , style: TextStyle(
fontSize: 18,
color: Colors.white,
),),
Text('/Week' , style: TextStyle(
fontSize: 11,
color: Colors.white60,
),),
],
),
Container(
width: 25,
height: 25,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(
color: Colors.white,
width: 1,
),
),
),
],
),
),
Radiobuttonwidget
//this array help us to manage the state of radio button.
var ischecked = [true, false, false];
class MyRadioButton extends StatefulWidget {
const MyRadioButton({Key? key}) : super(key: key);
#override
State<MyRadioButton> createState() => _MyRadioButtonState();
}
class _MyRadioButtonState extends State<MyRadioButton> {
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[0]=true;
ischecked[1]=false;
ischecked[2]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[0]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[0]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[1]=true;
ischecked[0]=false;
ischecked[2]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[1]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[1]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[0]=false;
ischecked[2]=true;
ischecked[1]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[2]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[2]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
],
);
}
}
SAmpleCode Dartpad live
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
shrinkWrap: true,
children: [MyRadioButton()],
),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}
var ischecked = [true, false, false];
class MyRadioButton extends StatefulWidget {
const MyRadioButton({Key? key}) : super(key: key);
#override
State<MyRadioButton> createState() => _MyRadioButtonState();
}
class _MyRadioButtonState extends State<MyRadioButton> {
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[0]=true;
ischecked[1]=false;
ischecked[2]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[0]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[0]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[1]=true;
ischecked[0]=false;
ischecked[2]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[1]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[1]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
child: InkWell(
onTap: (){
setState(() {
ischecked[0]=false;
ischecked[2]=true;
ischecked[1]=false;
});
},
child: Container(
decoration: BoxDecoration(
color: ischecked[2]?Colors.lightGreen:Colors.transparent,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
height: 65,
// width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: Text(
'1 WEEK',
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
),
),
Expanded(
flex: 2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'2.99',
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
),
Text(
'/Week',
style: TextStyle(
fontSize: 11,
color: Colors.black26,
),
),
],
),
),
Flexible(
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
color: ischecked[2]?Colors.red:Colors.transparent,
borderRadius: BorderRadius.circular(25),
border: Border.all(
color: Colors.black54,
width: 1,
),
),
),
),
],
),
),
),
),
],
);
}
}

How to fetch values from a form in flutter?

As per the image I have to fetch all the values from the required field i.e. from the TextFormField, CustomRadioButton & as well as from the patient age as per my requirement. On click of submit button I have to fetch those values so that I can pass them through the provider.
As I am very new to flutter, I can fetch the value from the TextFormField but couldnot able to fetch from rest of the two.
here is my UI below.
below is the code for CustomRadioButton
Container(
width: 200,
child: CustomRadioButton(
customShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
elevation: 0,
absoluteZeroSpacing: false,
unSelectedColor: Theme.of(context).canvasColor,
buttonLables: [
'Male',
'Female',
],
buttonValues: [
"MALE",
"FEMALE",
],
buttonTextStyle: ButtonTextStyle(
textStyle: TextStyle(fontSize: 10)),
radioButtonValue: (value) {
print(value);
},
width: 80,
height: 60,
enableShape: true,
selectedBorderColor: Colors.green,
unSelectedBorderColor: Color(0xFFD0D7EB),
selectedColor: Colors.green,
),
),
for the age picker(/do not know I am correct or not because I had just hardcoded the text 12, but want + and - should work./)
Container(
width: 100.0,
height: 55.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(7.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Center(
child: Icon(
Icons.remove,
color: Colors.black,
size: 20.0,
),
),
),
),
Text(
'12',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
color: Colors.black),
),
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Center(
child: Icon(
Icons.add,
color: Colors.black,
size: 20.0,
),
),
),
)
],
),
)
],
),
SizedBox(height: 80),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 40,
child: RaisedButton(
color: Color(0xFF888DA1),
child: Text('Submit', style: TextStyle(fontFamily: 'Poppins-Regular',
fontSize: 14, color: Colors.white)),
onPressed: (){
submit();
}
),
),
],
This one is the function where I will fetch those values
submit() async{
print(nameController.text);
}
Please help me how to do this!
So here what i do first set defaultSelected: "MALE", and then store value in one variable and when you change the value then you
get this value from radioButtonValue: this method then simply add this value to my local variable. After that for age i only added simple
increment and decrement logic and set this value to text
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
accentColor: Colors.blue,
),
home: SelectionScreen(),
);
}
}
class SelectionScreen extends StatefulWidget{
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return _selectionScreen();
}
}
class _selectionScreen extends State<SelectionScreen>{
var gender = "MALE";
int age = 12;
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: [
Container(
width: 200,
child: CustomRadioButton(
customShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
elevation: 0,
absoluteZeroSpacing: false,
unSelectedColor: Theme.of(context).canvasColor,
buttonLables: [
'Male',
'Female',
],
buttonValues: [
"MALE",
"FEMALE",
],
buttonTextStyle: ButtonTextStyle(
textStyle: TextStyle(fontSize: 10)),
radioButtonValue: (value) {
setState(() {
gender = value.toString();
print("=--->>${gender}");
});
},
width: 80,
height: 60,
enableShape: true,
selectedBorderColor: Colors.green,
unSelectedBorderColor: Color(0xFFD0D7EB),
selectedColor: Colors.green,
defaultSelected: "MALE",
),
),
Container(
width: 100.0,
height: 55.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
onTap: () {
setState(() {
age--;
});
},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(7.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Center(
child: Icon(
Icons.remove,
color: Colors.black,
size: 20.0,
),
),
),
),
Text(
age.toString(),
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
color: Colors.black),
),
InkWell(
onTap: () {
setState(() {
age++;
});
},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
border: Border.all(
color: Color(0xFFD0D7EB),
)
),
child: Center(
child: Icon(
Icons.add,
color: Colors.black,
size: 20.0,
),
),
),
)
],
),
),
SizedBox(height: 80),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 40,
child: RaisedButton(
color: Color(0xFF888DA1),
child: Text('Submit', style: TextStyle(fontFamily: 'Poppins-Regular',
fontSize: 14, color: Colors.white)),
onPressed: (){
print("============>> Radio Button Value: $gender");
print("============>> Age: $age");
}
),
),
],),
],
),),
);
}
}
The most direct way is to build a model class that will have the default values for each form element. Then, when building the form, construct an instance of the form data class, and use the members to establish the value: for each item. Wire up each of the onChanged: callbacks to validate the new value, and store it back into the form data instance. On submit, send the data along its merry way.

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,
),
],
),
),
],
),
),
],
),
);
}
}