Related
I have a page that the user can add students to the list by entering their name in the listtile in the listview, i wanted to have 2 specific radio buttons for each name one green one red for their presence or absence. I have created my version of it already but when you click on radio button it changes all in that column. is there any other way that this can be done?
1
2
my code:
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
class InsideList extends StatefulWidget {
final String name;
InsideList(this.name);
#override
State<InsideList> createState() => _InsideListState();
}
class _InsideListState extends State<InsideList> {
List<String> _students = [];
late int selectedRadio;
late TextEditingController _textController;
#override
void initState() {
super.initState();
_textController = TextEditingController();
selectedRadio = 0;
}
SetselectedRadio(int? val) {
setState(() {
selectedRadio = val!;
});
}
#override
void dispose() {
_textController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.name),
centerTitle: true,
backgroundColor: const Color.fromARGB(255, 22, 37, 50),
toolbarHeight: 65,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
),
body: _students.length > 0
? ListView.separated(
itemCount: _students.length,
itemBuilder: (_, index) {
return ListTile(
leading: const Icon(Icons.person),
trailing: FittedBox(
fit: BoxFit.fill,
child: Row(
children: [
Radio(
activeColor: Colors.green,
value: 0,
groupValue: selectedRadio,
onChanged: (val) {
SetselectedRadio(val);
}),
Radio(
activeColor: Colors.red,
value: 1,
groupValue: selectedRadio,
onChanged: (val) {
SetselectedRadio(val);
},
)
],
),
),
title: Center(child: Text(_students[index])),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) =>
InsideList(_students[index]))));
},
onLongPress: (() async {
await showDialog(
context: context,
builder: ((context) {
return AlertDialog(
title: const Text(
"Are you sure you want to delete this student?",
style: TextStyle(fontSize: 15),
),
actions: [
TextButton(
child: Text("cancel"),
onPressed: (() {
Navigator.pop(context);
})),
TextButton(
child: Text('Delete'),
onPressed: () {
setState(() {
_students.removeAt(index);
Navigator.pop(context);
});
},
),
],
);
}));
}),
);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(
color: Colors.black,
),
)
: const Center(
child: Text("You currently have no students. Add from below."),
),
floatingActionButton: SpeedDial(
animatedIcon: AnimatedIcons.menu_arrow,
spacing: 6,
spaceBetweenChildren: 6,
backgroundColor: const Color.fromARGB(255, 22, 37, 50),
foregroundColor: const Color.fromARGB(255, 255, 255, 255),
children: [
SpeedDialChild(
child: const Icon(Icons.group_add),
label: "add student",
onTap: () async {
final result = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Add a new student'),
content: TextField(
controller: _textController,
autofocus: true,
decoration: const InputDecoration(
hintText: "Enter the name of the student."),
),
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text('Add'),
onPressed: () {
Navigator.pop(context, _textController.text);
_textController.clear();
},
),
],
);
},
);
if (result != null) {
result as String;
setState(() {
_students.add(result);
});
}
},
),
],
),
);
}
}
It's because basically you are assigning same values for each Radio Button Group. There is a better way but I just have modified your code a bit to show you how to do it.
First, you assign a list for radio values along with students.
List<String> _students = [];
List<int> _selectedRadio = [];
And for assigning a value to a radio button, you need index of the radio button as well.
void _selectRadio(int index, int? val) {
setState(() {
_selectedRadio[index] = val ?? 0;
});
}
Then for Radio Buttons, assign a group value with index.
Radio(
activeColor: Colors.green,
value: 0,
groupValue: _selectedRadio[index],
onChanged: (val) {
_selectRadio(index, val);
},
),
Radio(
activeColor: Colors.red,
value: 1,
groupValue: _selectedRadio[index],
onChanged: (val) {
_selectRadio(index, val);
},
)
Then finally, when you create a student, you add a radio button value to the list of radio button value.
if (result != null) {
result as String;
setState(() {
_students.add(result);
_selectedRadio.add(0);
});
}
And below is the full working code. Hope this helps.
class InsideList extends StatefulWidget {
final String name;
InsideList(this.name);
#override
State<InsideList> createState() => _InsideListState();
}
class _InsideListState extends State<InsideList> {
List<String> _students = [];
List<int> _selectedRadio = [];
late TextEditingController _textController;
#override
void initState() {
super.initState();
_textController = TextEditingController();
}
void _selectRadio(int index, int? val) {
setState(() {
_selectedRadio[index] = val ?? 0;
});
}
#override
void dispose() {
_textController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.name),
centerTitle: true,
backgroundColor: const Color.fromARGB(255, 22, 37, 50),
toolbarHeight: 65,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
),
body: _students.length > 0
? ListView.separated(
itemCount: _students.length,
itemBuilder: (_, index) {
return ListTile(
leading: const Icon(Icons.person),
trailing: FittedBox(
fit: BoxFit.fill,
child: Row(
children: [
Radio(
activeColor: Colors.green,
value: 0,
groupValue: _selectedRadio[index],
onChanged: (val) {
_selectRadio(index, val);
}),
Radio(
activeColor: Colors.red,
value: 1,
groupValue: _selectedRadio[index],
onChanged: (val) {
_selectRadio(index, val);
},
)
],
),
),
title: Center(child: Text(_students[index])),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) =>
InsideList(_students[index]))));
},
onLongPress: (() async {
await showDialog(
context: context,
builder: ((context) {
return AlertDialog(
title: const Text(
"Are you sure you want to delete this student?",
style: TextStyle(fontSize: 15),
),
actions: [
TextButton(
child: Text("cancel"),
onPressed: (() {
Navigator.pop(context);
})),
TextButton(
child: Text('Delete'),
onPressed: () {
setState(() {
_students.removeAt(index);
_selectedRadio.removeAt(index);
Navigator.pop(context);
});
},
),
],
);
}));
}),
);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(
color: Colors.black,
),
)
: const Center(
child: Text("You currently have no students. Add from below."),
),
floatingActionButton: SpeedDial(
animatedIcon: AnimatedIcons.menu_arrow,
spacing: 6,
spaceBetweenChildren: 6,
backgroundColor: const Color.fromARGB(255, 22, 37, 50),
foregroundColor: const Color.fromARGB(255, 255, 255, 255),
children: [
SpeedDialChild(
child: const Icon(Icons.group_add),
label: "add student",
onTap: () async {
final result = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Add a new student'),
content: TextField(
controller: _textController,
autofocus: true,
decoration: const InputDecoration(
hintText: "Enter the name of the student."),
),
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text('Add'),
onPressed: () {
Navigator.pop(context, _textController.text);
_textController.clear();
},
),
],
);
},
);
if (result != null) {
result as String;
setState(() {
_students.add(result);
_selectedRadio.add(0);
});
}
},
),
],
),
);
}
}
You have to create List < int > SelectedRadio , which will always has your students list length. Next in method SetSelectedRadio you have to change value in SelectedRadio[student_index]
You have done it wrong you have given the radioButtons a single variable which all the radioButtons are referring to this cause them to share the same value and change accordingly(meaning all the radioButtons with corresponding values will change).
You can use various methods to pass this FOR EXAMPLE :
You can generate a secondary list that will hold all the bool values for each and every list item you can use list.generate() to generate the list depending on the length of the _student list.
You can create a model class where you save both name and the int value for the radio buttons (Most preferred as it gives more flexibility for future changes) I have mentioned the same below
Full code
// Here I have created the model class to create a list.
// do not make the arguments final as they will not change as we need them to change.
class student {
String nameOfStudent;
int isPresent;
student({
required this.nameOfStudent,
required this.isPresent,
});
}
class InsideList extends StatefulWidget {
final String name;
InsideList(this.name);
#override
State<InsideList> createState() => _InsideListState();
}
class _InsideListState extends State<InsideList> {
// As this list is not final one can change the values dynamically.
// You can add the items using _students.add(student(
// nameOfStudent: "Name",
// isPresent: 0,
// ));
List<student> _students = [];
late TextEditingController _textController;
#override
void initState() {
super.initState();
_textController = TextEditingController();
}
#override
void dispose() {
_textController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.name),
centerTitle: true,
backgroundColor: const Color.fromARGB(255, 22, 37, 50),
toolbarHeight: 65,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
),
body: _students.length > 0
? ListView.separated(
itemCount: _students.length,
itemBuilder: (_, index) {
return ListTile(
leading: const Icon(Icons.person),
trailing: FittedBox(
fit: BoxFit.fill,
child: Row(
children: [
Radio(
activeColor: Colors.green,
value: 0,
groupValue: _students[index].isPresent,
onChanged: (val) {
setState(() {
_students[index].isPresent = val!;
});
}),
Radio(
activeColor: Colors.red,
value: 1,
// this will go to the list with the idex and fetch the value
groupValue: _students[index].isPresent,
onChanged: (val) {
// this will assign a new value to the item with the corresponding index
// this will give each and every item its own radioButton variable resulting in proper value change for each item in the list.
setState(() {
_students[index].isPresent = val!;
});
},
)
],
),
),
title: Center(child: Text(_students[index].nameOfStudent)),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) =>
InsideList(_students[index]))));
},
onLongPress: (() async {
await showDialog(
context: context,
builder: ((context) {
return AlertDialog(
title: const Text(
"Are you sure you want to delete this student?",
style: TextStyle(fontSize: 15),
),
actions: [
TextButton(
child: Text("cancel"),
onPressed: (() {
Navigator.pop(context);
})),
TextButton(
child: Text('Delete'),
onPressed: () {
setState(() {
_students.removeAt(index);
Navigator.pop(context);
});
},
),
],
);
}));
}),
);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(
color: Colors.black,
),
)
: const Center(
child: Text("You currently have no students. Add from below."),
),
);
}
}
As I have mentioned there are many more ways to do the same (using Map as well) Hope this is help full and keep in mind about making variables final as it will not change will the application is running.
I want to change clicked icon colour when we click on icon but after 2 seconds it should remove the focus colour.
only the icon should be focused on clicking for 2 seconds then it should come back to normal.
basically, When we click on icon it gets the selected item colour, but I want it to be removed after 2 second.
Please help in this
Any help will be appreciated,Thanks in advance
child:Theme(
data: ThemeData(
splashFactory: InkRipple.splashFactory,
splashColor: Color(0xFF009EFB),
highlightColor: Color(0xFF009EFB),
),
child: BottomNavigationBar(
backgroundColor: Color(0xFFDADADA),
type: BottomNavigationBarType.fixed,
showUnselectedLabels: true,
showSelectedLabels: true,
currentIndex: appStore.currentIndex,
unselectedItemColor: textSecondaryColorGlobal,
unselectedLabelStyle: secondaryTextStyle(),
selectedLabelStyle: secondaryTextStyle(),
selectedItemColor: textSecondaryColorGlobal,
items: [
BottomNavigationBarItem(
icon: cachedImage('assets/hom.png', width: 20, height: 20, color: Theme.of(context).textTheme.subtitle1!.color),
activeIcon: cachedImage('assets/hom.png', width: 20, height: 20, color: Theme.of(context).textTheme.subtitle1!.color),
label: 'Home',
),
BottomNavigationBarItem(
icon: cachedImage('assets/shop.png', width: 20, height: 20, color: Theme.of(context).textTheme.subtitle1!.color),
activeIcon: cachedImage('assets/shop.png', width: 20, height: 20, color: Theme.of(context).textTheme.subtitle1!.color),
label: 'Shop',
),
],
onTap: (index) {
setState(() {
appStore.currentIndex = index;
appStore.setIndex(index);
});
if(appStore.currentIndex == 0) {
webViewController!.loadUrl(urlRequest: URLRequest(url: }
else if(appStore.currentIndex == 1) {
}
}),
)
Simply use state for button colour. Example for ElevatedButton:
class _MyWidget extends State<MyWidget> {
Color color = Colors.blue;
#override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: color),
child: const Text('Hello, World!'),
onPressed: () {
setState(() => {color = Colors.amber});
Future.delayed(const Duration(seconds: 2), () {
setState(() => {color = Colors.blue});
});
},
);
}
}
I have question I hope to help me How can I call the binding of page Home when I press the tap of home on bottom navbar
**Controller of bottom navbar **
class BottomNavBarController extends GetxController{
List bodyPage=[
const Home(),
const Settings(),
const ProfileView()
];
NavBar
body:Obx(()=> navBarController.currentPage,
),
// bodyPage[navBarController.indexNavBar],
bottomNavigationBar:Obx(()=> NavigationBar(
currentIndex: navBarController.indexNavBar.value,
items: [
NavigationBarItem(
icon: const Icon(home_outline, ),
),
NavigationBarItem(
icon: const Icon(setting_outline),
),
NavigationBarItem(
icon: const Icon(menu_outline),
)])));
**Binding **
class HomeBinding implements Bindings{
#override
void dependencies() {
Get.put(HomeController());
}}
**Get Page **
getPages: [
GetPage(name: "/home", page:()=> const HomeView(), binding:HomeBinding()),
]
I use bottom navigation and Getx.
In this way :
changeNavigationIndex(int index) {
myPresenter.setMainNavigationIndex(index);
switch (index) {
case 1:
setState(() {
mainNavigationTitle = txtTitle2;
});
break;
case 2:
setState(() {
mainNavigationTitle = txtTitle3;
});
break;
case 3:
setState(() {
mainNavigationTitle = txtTitle4;
});
break;
case 0:
default:
setState(() {
mainNavigationTitle = txtTitle1;
});
break;
}
}
buildBottomNavigationMenu(context, MyPresenter myPresenter) {
changeNavigationIndex(myPresenter.mainNavigationIndex);
return Obx(() =>
MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: SizedBox(
child: BottomNavigationBar(
onTap: changeNavigationIndex,
type: BottomNavigationBarType.fixed,
currentIndex: salesPresenter.mainNavigationIndex,
selectedIconTheme: IconThemeData(
color: CustomColors.iconColor,
size: 30,
),
items: [
BottomNavigationBarItem(
icon: const Icon(Icons.icon1),
label: txt1,
backgroundColor: Theme.of(context).primaryColor,
),
BottomNavigationBarItem(
icon: const Icon(Icons.icon2),
label: txt2,
backgroundColor: Theme.of(context).primaryColor,
),
BottomNavigationBarItem(
icon: const Icon(Icons.icon3),
label: txt3,
backgroundColor: Theme.of(context).primaryColor,
),
BottomNavigationBarItem(
icon: const Icon(Icons.icon4),
label: txt4,
backgroundColor: Theme.of(context).primaryColor,
),
],
),
)
));
}
return
WillPopScope(
onWillPop: () async => false,
child: Scaffold(
body:
: GetX<MyPresenter>(
builder: (mp) => IndexedStack(
index: mp.mainNavigationIndex,
children: const[
Screen1(),
Screen2(),
Screen3(),
Screen4(),
],
)
),
bottomNavigationBar: buildBottomNavigationMenu(context, myPresenter),
drawer: const MainDrawerWidget(),
),
);
So, In this app all Getx Binding is in separated file (MainBind.dart) That I call on Main.dart.
But if you want call the bind in same file that u have programmated the bottom navigation, you can put the bind in your Main Class like this:
class _MainScreenState extends State<MainScreen> {
Get.lazyPut<MyPresenter>(() => MyPresenter(), fenix: true);
}
I have a MainPage with bottomnavigation bar with bottomnavigation items. I want to call APIs of bottomnavigation item pages whenever i tap on it i.e I want to reload page everytime I vist the page.
But in my case its not reloading everytime but at once when mainpage called all api of bottomnavigation items page APIs are called attime.
MainPage
class MainPage extends StatefulWidget{
#override
_MainPageState createState() => new _MainPageState();
}
class _MainPageState extends State<MainPage>{
ListQueue<int> _navigationQueue = ListQueue();
int _selectedIndex = 0;
int counter = Constant.CART_COUNT;
List<GlobalKey<NavigatorState>> _navigatorKeys = [
GlobalKey<NavigatorState>(),
GlobalKey<NavigatorState>(),
GlobalKey<NavigatorState>(),
GlobalKey<NavigatorState>()
];
Future<void> secureScreen() async {
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
}
#override
void initState() {
// TODO: implement initState
super.initState();
secureScreen();
}
#override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_navigationQueue.isEmpty) return true;
setState(() {
_navigationQueue.removeLast();
int position = _navigationQueue.isEmpty ? 0 : _navigationQueue.last;
_selectedIndex = position;
});
return false;
},
child: Scaffold(
backgroundColor: Colors.white,
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectedIndex,
selectedItemColor: Colors.blueAccent,
showSelectedLabels: true,
showUnselectedLabels: false,
items: [
BottomNavigationBarItem(
icon: Icon(
FontAwesome.home,
color: Colors.grey,
),
label: 'Home',
activeIcon: Icon(
FontAwesome.home,
color: Colors.blueAccent,
),
),
BottomNavigationBarItem(
icon: Icon(
FontAwesome.product_hunt,
color: Colors.grey,
),
label: 'Products',
activeIcon: Icon(
FontAwesome.product_hunt,
color: Colors.blueAccent,
),
),
BottomNavigationBarItem(
icon: Icon(
FontAwesome.users,
color: Colors.grey,
),
label: 'Customers',
activeIcon: Icon(
FontAwesome.users,
color: Colors.blueAccent,
),
),
BottomNavigationBarItem(
icon: Icon(
FontAwesome.search_plus,
color: Colors.grey,
),
label: 'Order Details',
activeIcon: Icon(
FontAwesome.users,
color: Colors.blueAccent,
),
),
],
onTap: (index) {
if(_selectedIndex == _selectedIndex){
_navigationQueue.removeWhere((element) => element == index);
_navigationQueue.addLast(index);
setState(() {
this._selectedIndex = index;
});
}
},
),
body: Stack(
children: [
_buildOffstageNavigator(0),
_buildOffstageNavigator(1),
_buildOffstageNavigator(2),
_buildOffstageNavigator(3)
],
),
),
);
}
Map<String, WidgetBuilder> _routeBuilders(BuildContext context, int index) {
return {
'/': (context) {
return [
HomePage(),
ProductSearchPage(),
CustomerPage(),
OrdersPage()
].elementAt(index);
},
};
}
Widget _buildOffstageNavigator(int index) {
var routeBuilders = _routeBuilders(context, index);
return Offstage(
offstage: _selectedIndex != index,
child: Navigator(
key: _navigatorKeys[index],
onGenerateRoute: (routeSettings) {
return MaterialPageRoute(
builder: (context) => routeBuilders[routeSettings.name]!(context),
);
},
),
);
}
}
You have used an offstage widget which will just remove the ui from the stage. It wont reload when the index is changed. You have to create a list
List screens = [
HomePage(),
ProductSearchPage(),
CustomerPage(),
OrdersPage()
],
//Then in body use
body: screens[index]
You can set the api call in on Tap because all the pages will be initialized at a time that's why you are facing this issue.
Just check the condition on Tap for a currently selected index and write down the API call there.
So I loaded up my flutter project after a few hours of not working on it, and when I try to click on a button that is supposed to root me to a specific page, the whole app freezes. The last time I ran it, it was working fine, and I haven't changed anything. I have restarted the program, and my pc and it still freezes. All other button that root to pages work so I assume it is a problem with the code of that page. This is the entire code for that page:
import 'package:flutter/material.dart';
import 'package:workwise2/classes/taskClass.dart';
import 'package:workwise2/config.dart';
class TodoTasks extends StatefulWidget {
#override
_TodoTasksState createState() => _TodoTasksState();
}
class _TodoTasksState extends State<TodoTasks> {
Settings settings = Settings();
BottomNavBarConfig bottomNavBarConfig = BottomNavBarConfig();
List <Task> tasks = [
Task(title: "Maths HW", description: "Complete Q2, Q6 and Q7 with GPCs on Q8", subject: "maths", day: 12, month: 4, year: 2021),
Task(title: "English test", description: "Revise quotes for anger", subject: "english", day: 13, month: 4, year: 2021),
];
#override
Widget build(BuildContext context) {
int _currentIndex = 0;
String _requestedPage;
return Scaffold(
appBar: AppBar(
title: Text(
"Tasks",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30.0
),
),
backgroundColor: Colors.indigoAccent[700],
leading: Icon(Icons.check_box_rounded, size: 40.0,),
),
body: AnimatedContainer(
duration: Duration(milliseconds: 1700),
child: ListView.builder(
itemBuilder: (context, index) {
Color _checkButtonColour;
double _checkButtonElevation;
IconData _bookmark = Icons.bookmark_border;
if (tasks[index].state == "todo") {
_checkButtonColour = Colors.red[600];
_checkButtonElevation = 0.0;
}
else if (tasks[index].state == "doing") {
_checkButtonColour = Colors.amber;
_checkButtonElevation = 5.0;
}
else if (tasks[index].state == "done") {
_checkButtonColour = Colors.green;
_checkButtonElevation = 10.0;
}
while (tasks[index].favourited == true) {
_bookmark = Icons.bookmark;
}
while (tasks[index].favourited == false) {
_bookmark = Icons.bookmark_border;
}
return Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 3.0),
child: Card(
elevation: 10.0,
child: ListTile(
contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 5.0),
onTap: () {},
leading: IconButton(
onPressed: () {
tasks[index].favourited = !tasks[index].favourited;
print(tasks[index].favourited);
},
icon: Icon(_bookmark),
iconSize: 35.0,
color: settings.subjectColours[tasks[index].subject]
),
title: Text(tasks[index].title, maxLines: 1, overflow: TextOverflow.fade,),
subtitle: Text(tasks[index].description, maxLines: 1, overflow: TextOverflow.ellipsis,),
trailing: AnimatedContainer(
height: 80.0,
width: 100.0,
duration: Duration(milliseconds: 1700),
child: Row(
children: <Widget> [
SizedBox(
width: 40.0,
height: 40.0,
child: MaterialButton(
elevation: _checkButtonElevation,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.0)),
onPressed: () {
if (tasks[index].state == "todo") {
setState(() {
tasks[index].state = "doing";
});
} else if (tasks[index].state == "doing") {
setState(() {
tasks[index].state = "done";
});
} else if (tasks[index].state == "done") {
setState(() {
tasks[index].state = "todo";
});
}
},
padding: EdgeInsets.all(2.0),
color: _checkButtonColour,
),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.more_vert),
)
],
),
),
),
),
);
},
itemCount: tasks.length,
)
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
backgroundColor: Colors.indigoAccent[700],
fixedColor: Colors.white,
unselectedFontSize: bottomNavBarConfig.unactiveTextSize,
unselectedIconTheme: IconThemeData(
size: bottomNavBarConfig.unactiveIconSize
),
selectedFontSize: bottomNavBarConfig.activeTextSize,
selectedIconTheme: IconThemeData(
size: bottomNavBarConfig.activeIconSize
),
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.check_box_rounded),
label: "Tasks"
),
BottomNavigationBarItem(
icon: Icon(Icons.lightbulb),
label: "Learn"
),
BottomNavigationBarItem(
icon: Icon(Icons.home_rounded),
label: "Home"
),
BottomNavigationBarItem(
icon: Icon(Icons.library_books_rounded),
label: "Notes"
),
],
onTap: (index) {
if (index == 0) {
_requestedPage = "/todotasks";
}
else if (index == 2) {
_requestedPage = "/home";
}
else if (index == 3) {
_requestedPage = "/notes";
}
else if (index == 1) {
_requestedPage = "/sets";
}
setState(() {
_currentIndex = index;
});
Navigator.popAndPushNamed(context, _requestedPage);
},
)
);
}
}
I don't know what is wrong. Please help me I have no clue what to do. Comment for more details.
This was caused due to the two while statements in my code. They basically called each other and froze the app.
Use
Navigator.of(context).pushNamedUntil(_requestedPage);