How to make a Persistent BottomAppBar? - flutter

I made a BottomAppbar and a FAB at the center of a screen. The BottomAppbar is working fine, moving by indexes but now I want to make it persistent across all screens whenever I navigate.
Here is the current code:
class BottomNavBar extends StatefulWidget {
#override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
int currentTab = 0;
final List<Widget> screens = [
MenuPage(),
OffersPage(),
ProfilePage(),
MorePage(),
HomePage(),
];
final PageStorageBucket buckets = PageStorageBucket();
Widget currentScreen = HomePage();
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
notchMargin: 20,
child: SizedBox(
height: 80,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = MenuPage();
currentTab = 4;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/menu.png',
color: currentTab == 4
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
SizedBox(height: 0.2 * kDefaultPadding),
Text(
'Menu',
style: Theme.of(context).textTheme.caption!.copyWith(
color: currentTab == 4
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
),
],
),
),
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = OffersPage();
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/offers.png',
color: currentTab == 1
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
SizedBox(height: 0.2 * kDefaultPadding),
Text(
'Offers',
style: Theme.of(context).textTheme.caption!.copyWith(
color: currentTab == 1
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
)
],
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = ProfilePage();
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/profile.png',
color: currentTab == 2
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
Text(
'Profile',
style: Theme.of(context).textTheme.caption!.copyWith(
color: currentTab == 2
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
),
],
),
),
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = MorePage();
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/more.png',
color: currentTab == 3
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
Text(
'Menu',
style: Theme.of(context).textTheme.caption!.copyWith(
color: currentTab == 3
? kPrimaryColor
: Colors.grey.withOpacity(0.5),
),
)
],
),
),
],
),
],
),
),
),
floatingActionButton: FloatingActionButton(
backgroundColor:
currentTab == 0 ? kPrimaryColor : Colors.grey.withOpacity(0.5),
onPressed: () {
setState(() {
currentScreen = HomePage();
currentTab = 0;
});
},
child: const Icon(
Icons.home,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body: PageStorage(
bucket: buckets,
child: currentScreen,
),
);
}
}

Related

Null Check Operator Used On a Null Value? GetStorage in flutter give me this error

I am using GetStorage package in Flutter to check if the current user is login or not but it gives the error.
For example, when a user does not login it shows the null error and when I login it then it is filn, check if you can.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:mobihub_2/Screens/main_login.dart';
import 'package:mobihub_2/Screens/navigationscreens.dart/add.dart';
import 'navigationscreens.dart/adds.dart';
import 'navigationscreens.dart/chat.dart';
import 'navigationscreens.dart/home2.dart';
import 'navigationscreens.dart/person.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
// ignore: library_private_types_in_public_api
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
final auth = FirebaseAuth.instance;
int currentTab = 0;
final List<Widget> screens = const [
Home2(),
Chat(),
Youradds(),
Account(),
];
final PageStorageBucket bucket = PageStorageBucket();
Widget currentScreen = const Home2();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey.shade100,
body: PageStorage(
bucket: bucket,
child: currentScreen,
),
floatingActionButton: FloatingActionButton(
backgroundColor: const Color(0xFFFFDC3D),
elevation: 2.5,
onPressed: () {
if(FirebaseAuth.instance.currentUser != null){
Navigator.push(context,
MaterialPageRoute(builder: (context) => const AddItems()));
}else{
Navigator.push(context,
MaterialPageRoute(builder: (context) => MainLogin()));
}
},
child: const Icon(
Icons.add,
color: Colors.black,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
color: Colors.white,
shape: const CircularNotchedRectangle(),
notchMargin: 10,
child: SizedBox(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
highlightElevation: 0.0,
highlightColor: Colors.white,
hoverColor: Colors.white,
hoverElevation: 0.0,
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = const Home2();
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.home,
color: currentTab == 0
? const Color(0xFFFFDC3D)
: Colors.black,
size: 25,
),
Text(
'',
style: TextStyle(
color: currentTab == 0
? const Color(0xFFFFDC3D)
: Colors.white),
)
],
),
),
MaterialButton(
highlightElevation: 0.0,
highlightColor: Colors.white,
hoverColor: Colors.white,
hoverElevation: 0.0,
minWidth: 40,
onPressed: () {
setState(() {
if(FirebaseAuth.instance.currentUser != null){
currentScreen = const Chat();
currentTab = 1;
}else{
Navigator.push(context,
MaterialPageRoute(builder: (context) => MainLogin()));
}
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.chat,
color: currentTab == 1
? const Color(0xFFFFDC3D)
: Colors.black,
size: 25,
),
Text(
'',
style: TextStyle(
color: currentTab == 1
? const Color(0xFFFFDC3D)
: Colors.white),
)
],
),
)
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
highlightElevation: 0.0,
highlightColor: Colors.white,
hoverColor: Colors.white,
hoverElevation: 0.0,
minWidth: 40,
onPressed: () {
setState(() {
if(FirebaseAuth.instance.currentUser != null){
currentScreen = const Youradds();
currentTab = 2;
}else{
Navigator.push(context,
MaterialPageRoute(builder: (context) => MainLogin()));
}
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.favorite,
color: currentTab == 2
? const Color(0xFFFFDC3D)
: Colors.black,
size: 25,
),
Text(
'',
style: TextStyle(
color: currentTab == 2
? const Color(0xFFFFDC3D)
: Colors.white),
)
],
),
),
MaterialButton(
highlightElevation: 0.0,
highlightColor: Colors.white,
hoverColor: Colors.white,
hoverElevation: 0.0,
autofocus: false,
minWidth: 40,
onPressed: () {
setState(() {
if(FirebaseAuth.instance.currentUser != null){
currentScreen = Account();
currentTab = 3;
}else{
Navigator.push(context,
MaterialPageRoute(builder: (context) => MainLogin()));
}
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.person,
color: currentTab == 3
? const Color(0xFFFFDC3D)
: Colors.black,
size: 25,
),
Text(
'',
style: TextStyle(
color: currentTab == 3
? const Color(0xFFFFDC3D)
: Colors.white),
)
],
),
)
],
)
],
),
),
),
);
}
}
I need help if anyone expert in Flutter checks my code and gives me the right answer. Thank you in advance.

Why its show overflow when I am going to using seState() function?

Normally all things is good but when I want to add setState() it show overflow. I am making an BMI calculator app and i create a custom button and i think there the problem started.
import 'package:flutter/material.dart';
class RoundIconButton extends StatelessWidget {
RoundIconButton({required this.icon, required this.tap});
final IconData icon;
final Function tap;
#override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: tap(),
child: Icon(
icon,
color: Color(0xffFF8B00),
),
elevation: 6.0,
constraints: BoxConstraints.tightFor(
width: 40.0,
height: 47.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
fillColor: Colors.black,
);
}
}
import 'package:bmi_calculator/round_icon_button.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'reusable_card.dart';
import 'iconText.dart';
import 'constants.dart';
enum Gender {
male,
female,
}
class InputPage extends StatefulWidget {
const InputPage({Key? key}) : super(key: key);
#override
State<InputPage> createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
Gender? selectedGender;
int height = 180;
int weight = 50;
int age = 18;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.black,
title: Text('BMI Calculator'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.male;
print('Male tapped');
});
},
child: ReuseableCard(
colour: selectedGender == Gender.male
? kactiveCardColor
: kinactiveCardColor,
cardChild: iconText(
icon: FontAwesomeIcons.mars,
lable: 'Male',
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.female;
print('Female Tapped');
});
},
child: ReuseableCard(
colour: selectedGender == Gender.female
? kactiveCardColor
: kinactiveCardColor,
cardChild: iconText(
icon: FontAwesomeIcons.venus,
lable: 'FeMale',
),
),
),
),
],
),
),
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Height'.toUpperCase(),
style: klableTextStylet,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
height.toString(),
style: kNumberTextStyle,
),
Text('cm'),
],
),
SliderTheme(
data: SliderTheme.of(context).copyWith(
overlayColor: Colors.red,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15),
overlayShape: RoundSliderOverlayShape(overlayRadius: 30),
),
child: Slider(
value: height.toDouble(),
max: 220.0,
min: 50.0,
inactiveColor: Colors.yellow,
activeColor: Colors.black,
thumbColor: Colors.red,
onChanged: (double newValue) {
setState(() {
height = newValue.round();
print(newValue);
});
},
),
),
],
),
),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Weight'.toUpperCase(),
style: klableTextStylet,
),
Text(
weight.toString(),
style: kNumberTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundIconButton(
tap: (){
setState(() {
weight++;
});
},
icon: FontAwesomeIcons.plus,
),
SizedBox(
width: 10,
),
RoundIconButton(
tap: (){
setState(() {
weight--;
});
},
icon: FontAwesomeIcons.minus,
),
],
),
],
),
),
),
Expanded(
child: ReuseableCard(
colour: Color(0xffFF8B00),
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Age'.toUpperCase(),
style: klableTextStylet,
),
Text(
age.toString(),
style: kNumberTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RoundIconButton(
tap: (){
setState(() {
age++;
});
},
icon: FontAwesomeIcons.plus,
),
SizedBox(
width: 10,
),
RoundIconButton(
tap: (){
setState(() {
age--;
});
},
icon: FontAwesomeIcons.minus,
),
],
),
],
),
),
),
],
),
),
Container(
child: Center(
child: Text(
'Your BMI Calculator',
style: TextStyle(
color: Color(0xffFF8B00),
),
)),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15), topRight: Radius.circular(15)),
),
width: double.infinity,
height: kbottomContainerHeight,
margin: EdgeInsets.only(top: 10),
),
],
),
);
}
}
In above code i want to add setstate function in RoundIconButton but when i try to add this it show overflow.I am expecting this But getting this
try Wrapping your scaffold body's Column with SingleChildScrollView it should fix the issue!
There are two possible solutions.
wrap your widget with SingleChildScrollview.
for example
body: SingelChildScrollView(
scrolldirection : Axis.horizontal
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedGender = Gender.male;
print('Male tapped');
});
},
Remove above expanded you are using two Expanded widgets and both need some space on screen and the first Expanded is covering whole screen remove one of the extra Expanded widgets and wrap whole row with one single expanded.
I got the answer. Its about the old version of flutter. On flutter 2.0 we can do:
final Function tap;
onPresed: tap(),
but in flutter 3.0+ we have to do:
final Function() tap;
onPresed: tap,
class RoundIconButton extends StatelessWidget {
RoundIconButton({required this.icon, required this.tap});
final IconData icon;
final Function() tap; // add bracket here ?
#override
Widget build(BuildContext context) {
return RawMaterialButton(
onPressed: tap(),
child: Icon(
icon,
color: Color(0xffFF8B00),
),
elevation: 6.0,
constraints: BoxConstraints.tightFor(
width: 40.0,
height: 47.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
fillColor: Colors.black,
);
}
}

how to solve that buttom navigation bar doesn't appear in flutter

First,, Thanks for answering of questions about flutter in everytime.
As explaining the way this time, I tried to make that seperating button navigation bar as a widget in another file from main file and try to use it in main file like below. but it doesn't appear and not specific error.. so I don't get why is it not apper and how to use this in the way that I tried to? Could you give me some advice about this? Thanks a lot.
--main page I used--
return Scaffold(
bottomNavigationBar: BottomBar(),
--bottomNavigationBar widget page--
class BottomBar extends StatefulWidget {
const BottomBar({Key? key}) : super(key: key);
#override
State<BottomBar> createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBar> {
int currentTab = 0;
final List<Widget> screens = [
HomePage(),
ShopPage(),
PeoplePage(),
WalletPage()
];
final PageStorageBucket bucket = PageStorageBucket();
Widget currentScreen = HomePage();
#override
Widget build(BuildContext context) {
return Scaffold(
body: PageStorage(
child: currentScreen,
bucket: bucket,
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: (){},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 10,
child: Container(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = HomePage();
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.home,
color: currentTab == 0? Colors.blue : Colors.grey,
),
Text(
'Home',
style: TextStyle(
color: currentTab == 0? Colors.blue : Colors.grey,
),
)
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = ShopPage();
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.shop,
color: currentTab == 1? Colors.blue : Colors.grey,
),
Text(
'Shop',
style: TextStyle(
color: currentTab == 1? Colors.blue : Colors.grey,
),
)
],
),
),
],
),
//Right Tab Bar Icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = WalletPage();
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.wallet,
color: currentTab == 2? Colors.blue : Colors.grey,
),
Text(
'Home',
style: TextStyle(
color: currentTab == 3? Colors.blue : Colors.grey,
),
)
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = PeoplePage();
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.people,
color: currentTab == 3? Colors.blue : Colors.grey,
),
Text(
'Shop',
style: TextStyle(
color: currentTab == 3? Colors.blue : Colors.grey,
),
)
],
),
),
],
),
],
),
),
),
);
}
}
It is likely due to the fact that your BottomBar class' build method contains a Scaffold and it should not. It should only return a BottomAppBar widget. You can move all of your FAB widget code to the outer scaffold in your Main Page class.

how to change icon color when navigate to another page in flutter?

I made a BottomBar and make them enable to navigate to the other pages using onPressed function like below codes. but after navigating to other page that'd be can't change icon color because I think i made bottomnavigationbar: BottomBar in other page so that the page build BottomBar newly and 'int current Tab=0' is build again..
how can I change the way to can be change icon's color?
--BottomBar--
class BottomBar extends StatefulWidget {
const BottomBar({Key? key}) : super(key: key);
#override
State<BottomBar> createState() => BottomBarState();
}
class BottomBarState extends State<BottomBar> {
int currentTab = 0;
PageStorageBucket bucket = PageStorageBucket();
Widget currentScreen = HomePage();
final List<Widget> screens = [
HomePage(),
ShopPage(),
PeoplePage(),
WalletPage()
];
#override
Widget build(BuildContext context) {
return BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 10,
child: Container(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = HomePage();
currentTab = 0;
});
Navigator.push(
context, MaterialPageRoute(builder: (context)=> HomePage())
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.home,
color: currentTab == 0? Colors.blue : Colors.grey,
),
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = ShopPage();
});
Navigator.push(
context, MaterialPageRoute(builder: (context)=> const ShopPage())
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.shop,
color: currentTab == 1? Colors.blue : Colors.grey,
),
],
),
),
],
),
//Right Tab Bar Icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = WalletPage();
currentTab = 2;
});
Navigator.push(
context, MaterialPageRoute(builder: (context)=> const WalletPage())
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.wallet,
color: currentTab == 2? Colors.blue : Colors.grey,
),
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = PeoplePage();
currentTab = 3;
});
Navigator.push(
context, MaterialPageRoute(builder: (context)=> PeoplePage())
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.people,
color: currentTab == 3? Colors.blue : Colors.grey,
),
],
),
),
],
),
],
),
),
);
}
}
--the way I used BottomBar in the other page--
bottomNavigationBar: BottomBar(),
Consider trying this :
return SafeArea(
child: Scaffold(
extendBody: true,
body:pageOPtions[selectedPage]
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: const Color(0xff282828),
currentIndex: selectedPage, //let's say it's 0
selectedLabelStyle: cardSecondaryTextStyle,
unselectedLabelStyle: cardSecondaryTextStyle,
selectedItemColor: const Color(0xffc8332c),
unselectedItemColor: const Color(0xff707070),
selectedIconTheme: const IconThemeData(color: Color(0xffc8332c)),
onTap: (index) {
setState(() {
selectedPage = index;
});
},
items: [
const BottomNavigationBarItem(
icon: Icon(
Icons.person,
color: Color(0xff707070),
size: 16,
),
activeIcon: Icon(
Icons.person,
color: Color(0xffc8332c),
size: 22,
),
label: 'Profile',
),
const BottomNavigationBarItem(
icon: Icon(
Icons.history,
color: Color(0xff707070),
size: 16,
),
activeIcon: Icon(
Icons.history,
color: Color(0xffc8332c),
size: 22,
),
label: 'Orders',
),
where pageOptions can be your screens like :
final pageOptions = [
const GeneralSettingsForm(),
const OrdersAndDelivery(),
];

Flutter one time choice radio buttons

How can i make one time choice custom radio button like in the picture
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selection = 0;
selectTime(int timeSelected) {
setState(() {
_selection = timeSelected;
});
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Container(
padding: EdgeInsets.all(30),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_selection = 1;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 1 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 1,
),
Text(
"11:00 - 12:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
),
InkWell(
onTap: () {
setState(() {
_selection = 2;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 2 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 2,
),
Text(
"12:00 - 13:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
)
],
),
],
)),
));
}
}