Exception caught by widgets library in bottom navigation bar - flutter

Hi, anyone know what the problem is? I'm trying to add a bottom navigation bar, but the following message is showing i tried to add bottom navigation bar and this is the code i made.
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Builder(builder: (context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedFontSize: 12,
unselectedItemColor: Colors.grey,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Beranda',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Akademik',
),
BottomNavigationBarItem(
icon: Icon(Icons.credit_card),
label: 'Pembayaran',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
selectedItemColor: primaryColor,
onTap: (index) {
setState(
() {
_selectedIndex = index;
},
);
},
),
body: Column(
children: [
_widgetOptions.elementAt(_selectedIndex),
body(),
],
),
);
}),
),
);
}
but when I try to run it the following error occurs, and I feel a little confused, I've tried to find some references but still can't find a solution that fits my case
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
lib\main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:62216/ZIcDnqzIkLk=/ws
E/SurfaceSyncer( 7593): Failed to find sync for id=0
W/Parcel ( 7593): Expecting binder but got null!
D/EGL_emulation( 7593): app_time_stats: avg=7.90ms min=2.99ms max=180.93ms count=62
D/EGL_emulation( 7593): app_time_stats: avg=15.06ms min=3.37ms max=21.43ms count=60
════════ Exception caught by widgets library ═══════════════════════════════════
The following StackOverflowError was thrown building Builder:
Stack Overflow
The relevant error-causing widget was
Builder
lib\…\homepage\home_page.dart:31
When the exception was thrown, this was the stack
this my home_page.dart
class HomePage extends StatefulWidget {
const HomePage({super.key});
#override
State<HomePage> createState() => _HomePageState();
}
int _selectedIndex = 0;
final List<Widget> _widgetOptions = <Widget>[
const HomePage(),
const AcademicPage(),
const CreditPage(),
const ProfilePage(),
];
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedFontSize: 12,
unselectedItemColor: Colors.grey,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Beranda',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Akademik',
),
BottomNavigationBarItem(
icon: Icon(Icons.credit_card),
label: 'Pembayaran',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
selectedItemColor: primaryColor,
onTap: (index) {
setState(
() {
_selectedIndex = index;
},
);
},
),
body: Column(
children: [
_widgetOptions.elementAt(_selectedIndex),
body(),
],
),
),
),
);
}
Widget body() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 30,
),
Container(
child: FutureBuilder<UserBiodata>(
future: AuthProvider().getDataMahasiswa(),
builder: (context, snapshot) {
if (snapshot.hasData) {
// return Text(snapshot.data!.status);
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${snapshot.data!.data.name}',
style: bold4,
),
Text(
'${snapshot.data!.data.prodi}',
style: bold6,
),
Text(
'Semester ${snapshot.data!.data.smt}',
style: regular6,
)
],
),
Image.asset(
'assets/images/user.png',
width: 60,
),
],
);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return const CircularProgressIndicator();
},
),
),
const SizedBox(
height: 30,
),
Image.asset(
'assets/images/statis.png',
),
const SizedBox(
height: 30,
),
Text(
'Akses Cepat',
style: bold4,
),
const SizedBox(
height: 18,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(1, 2), // changes position of shadow
),
],
),
child: Column(
children: [
const SizedBox(
height: 10,
),
Image.asset(
'assets/images/icon_jadwal.png',
height: 40,
),
const SizedBox(
height: 12,
),
Text(
'Jadwal Kuliah',
style: regular7,
)
],
),
),
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(1, 2), // changes position of shadow
),
],
),
child: Column(
children: [
const SizedBox(
height: 10,
),
Image.asset(
'assets/images/icon_jadwal.png',
height: 40,
),
const SizedBox(
height: 12,
),
Text(
'Jadwal Kuliah',
style: regular7,
)
],
),
),
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(1, 2), // changes position of shadow
),
],
),
child: Column(
children: [
const SizedBox(
height: 10,
),
Image.asset(
'assets/images/icon_jadwal.png',
height: 40,
),
const SizedBox(
height: 12,
),
Text(
'Jadwal Kuliah',
style: regular7,
)
],
),
),
],
),
const SizedBox(
height: 18,
),
Text(
'Dosen',
style: bold4,
),
const SizedBox(
height: 18,
),
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(1, 2), // changes position of shadow
),
],
),
child: Padding(
padding: const EdgeInsets.all(14),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Muhamad Fahmi Nugraha M.Kom',
style: bold6,
),
Text(
'kaprodi Fakultas Komputer',
style: bold7,
),
const SizedBox(
height: 12,
),
Row(
children: [
Container(
width: 94,
height: 32,
child: TextButton(
onPressed: () => showDialog(
context: context,
builder: (BuildContext context) =>
_signOutDialog(context),
),
style: TextButton.styleFrom(
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"WhatsApp",
style: boldButton1,
),
),
),
const SizedBox(
width: 8,
),
Container(
width: 94,
height: 32,
child: TextButton(
onPressed: (() {
var result = Navigator.pushNamed(
context,
AppRoute.biodataeRoute,
);
}),
style: TextButton.styleFrom(
backgroundColor: button,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Detail",
style: boldButton2,
),
),
),
],
)
],
),
Image.asset(
'assets/images/user.png',
width: 50,
)
],
),
),
),
const SizedBox(
height: 18,
),
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(1, 2), // changes position of shadow
),
],
),
child: Padding(
padding: const EdgeInsets.all(14),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Muhamad Fahmi Nugraha M.Kom',
style: bold6,
),
Text(
'kaprodi Fakultas Komputer',
style: bold7,
),
const SizedBox(
height: 12,
),
Row(
children: [
Container(
width: 94,
height: 32,
child: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"WhatsApp",
style: boldButton1,
),
),
),
const SizedBox(
width: 8,
),
Container(
width: 94,
height: 32,
child: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: button,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Detail",
style: boldButton2,
),
),
),
],
)
],
),
Image.asset(
'assets/images/user.png',
width: 50,
)
],
),
),
),
],
);
}
}
Widget _signOutDialog(BuildContext context) {
return AlertDialog(
title: Column(
children: [
Image.asset(
'assets/images/ic_lgt.png',
)
],
),
content: const Text('Apakah kamu yakin ingin logout?'),
actions: <Widget>[
TextButton(
onPressed: () => AuthProvider().signOut(context),
child: const Text('Ya'),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text(
'TIDAK',
style: TextStyle(color: Colors.red),
),
),
],
);
}

replace your code with this.
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child:Scaffold(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedFontSize: 12,
unselectedItemColor: Colors.grey,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Beranda',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Akademik',
),
BottomNavigationBarItem(
icon: Icon(Icons.credit_card),
label: 'Pembayaran',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: _selectedIndex,
selectedItemColor: primaryColor,
onTap: (index) {
setState(
() {
_selectedIndex = index;
},
);
},
),
body: Column(
children: [
_widgetOptions.elementAt(_selectedIndex),
body(),
],
),
),
),
);
}

Related

How to change circularprogressindicator in Center

I'm having a little problem here, I want to map a circularprogressindicator in the middle of the page but it just appears in the top center of the page, how do I move it to the middle of the page, I've tried wrapping it using the Column widget but an error occurs. How do I solve this simple problem.
and one more how do I add a hintText in the dropdown as the default value, because the dropdown immediately takes the value 1.
Thank you.
note:
green color for dropdown case
red for circularprogressindicator cases
Here I attach the code.
class JadwalKuliah extends StatefulWidget {
const JadwalKuliah({super.key});
#override
State<JadwalKuliah> createState() => _JadwalKuliahState();
}
class _JadwalKuliahState extends State<JadwalKuliah> {
String? _selectedItem1;
List<int> listitems = [1, 2, 3, 4, 5, 6, 7, 8];
int semester = 1;
List<Datum> data = [];
#override
void initState() {
super.initState();
fetchData(semester);
}
fetchData(int smt) async {
final apiResponse = await JadwalKuliahProvider.getJadwalKuliah(smt);
setState(() {
data = (apiResponse);
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: CustomAppbar(
title: 'Jadwal Kuliah',
),
),
body: Center(
child: Padding(
padding: const EdgeInsets.only(
left: 14,
top: 14,
right: 14,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Header(),
listJadwal(),
],
),
),
),
);
}
Widget Header() {
return Container(
padding: const EdgeInsets.only(left: 12, right: 8),
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1,
2,
),
),
],
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
// hint: const Text('Pilih Semester'),
value: semester,
onChanged: (value) {
setState(
() {
semester = value!;
},
);
fetchData(value!);
},
hint: const SizedBox(
width: 150, //and here
child: Text(
"Pilih Semester",
style: TextStyle(color: Colors.grey),
),
),
items: listitems.map(
(itemone) {
return DropdownMenuItem(
value: itemone, child: Text(itemone.toString()));
},
).toList(),
),
),
);
}
Widget listJadwal() {
return FutureBuilder<List<Datum>>(
future: JadwalKuliahProvider.getJadwalKuliah(semester),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Expanded(
child: ListView.builder(
padding: const EdgeInsets.only(
top: 10,
),
physics: const BouncingScrollPhysics(),
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 14),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(
10,
),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1, 2), // changes position of shadow
),
],
),
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
// "Audit Bank Syariah (SPI)",
snapshot.data![index].nmMk.toString(),
style: bold6,
),
Text(
snapshot.data![index].dosenAjar!.nmDosen.toString(),
style: regular7,
),
Text(
// "Perbankan Syariah",
snapshot.data![index].prodi.toString(),
style: regular7,
),
const SizedBox(
height: 5,
),
Row(
children: [
Container(
height: 30,
width: 70,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.location_on_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
Text(
'A201',
// snapshot.data![index]
// .dosenAjar!.nmDosen
// .toString(),
style: bold6.copyWith(color: greyColor),
),
],
),
),
),
const SizedBox(
width: 10,
),
Container(
height: 30,
width: 120,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.watch_later_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
const SizedBox(
width: 3,
),
Text(
// snapshot
// .data![index].jamAwal
// .toString(),
'09:00',
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'-',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'12:00',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
],
),
),
),
const SizedBox(
width: 10,
),
SizedBox(
height: 30,
width: 100,
child: ElevatedButton.icon(
onPressed: () {},
icon: const Icon(
Icons.download,
size: 17,
color: Color(0xffCEE1FF),
),
label: Text(
'Materi',
style: bold6,
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff0062FF),
),
),
),
],
),
const SizedBox(
height: 10,
),
Container(
width: double.infinity,
height: 38,
child: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffC9F7F5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Absen",
style: bold5.copyWith(
color: const Color(
0xff1BC5BD,
),
),
),
),
),
],
),
),
);
}),
);
} else {
return Center(
child: CircularProgressIndicator(color: primaryColor),
);
}
},
);
In your listJadwal change CircularProgressIndicator to this:
} else {
return Expanded(
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
);
}
Try below code I have same issue occurred I resolve this following code:
SizedBox(
height: MediaQuery.of(context).size.height / 1.0,//change on your need
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
),
Try this, Column will use your full screen size to center the widget
body: Column(mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: CircularProgressIndicator(),
)
],),

emoji_picker_flutter is not showing

I have a problem. I would like to use emoji_picker_flutter. This should be displayed under the TextInputField but is not displayed. What is the reason for this? Do I have to implement it differently or what is the reason? I tried to add the Config, but it did not change anything.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/foundation.dart' as foundation;
import '../Model/ChatModel.dart';
class IndidivdualPage extends StatefulWidget {
final ChatModel chatModel;
const IndidivdualPage({Key? key, required this.chatModel}) : super(key: key);
#override
_IndividualPageState createState() => _IndividualPageState();
}
class _IndividualPageState extends State<IndidivdualPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
leadingWidth: 70,
titleSpacing: 0,
leading: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.arrow_back, size: 24,),
CircleAvatar(
child: SvgPicture.asset(widget.chatModel.isGroup ? "assets/account-group.svg" : "assets/account.svg",
color: Colors.white, height: 34, width: 34),
radius: 20,
backgroundColor: Colors.lightBlue,
),
],
),
),
title: InkWell(
onTap: () {},
child: Container(
margin: EdgeInsets.all(6),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.chatModel.name, style: TextStyle(
fontSize: 18.5,
fontWeight: FontWeight.bold
),),
Text("last seend today at 15:03", style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal
),)
],
),
),
),
actions: [
IconButton(onPressed: () {}, icon: Icon(Icons.videocam)),
IconButton(onPressed: () {}, icon: Icon(Icons.call)),
PopupMenuButton<String>(
onSelected: (value){
print(value);
},
itemBuilder: (BuildContext context){
return [
PopupMenuItem(child: Text("View Contact"), value:"View Contact",),
];
})
],
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
ListView(),
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
children: [
Container(
width: MediaQuery.of(context).size.width - 60,
child:
Card(
margin: EdgeInsets.only(left: 2, right: 2, bottom: 8),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
child: TextFormField(
textAlignVertical: TextAlignVertical.center,
keyboardType: TextInputType.multiline,
maxLines: 5,
minLines: 1,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Send a message",
prefixIcon: IconButton(icon: Icon(Icons.emoji_emotions), onPressed: () { },),
suffixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.attach_file)),
IconButton(onPressed: () {}, icon: Icon(Icons.camera_alt)),
],
),
contentPadding: EdgeInsets.all(5),
),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8, right: 5, left: 2),
child: CircleAvatar(
radius: 25,
backgroundColor: Colors.lightBlue,
child: IconButton(icon: Icon(Icons.mic),color: Colors.white, onPressed: () {},),
),
),
],
),
emojiSelect(),
],
)
)
],
),
),
);
}
Widget emojiSelect() {
return EmojiPicker(
onEmojiSelected: (Category? category, Emoji? emoji) {
print(emoji);
},
onBackspacePressed: () {
// Do something when the user taps the backspace button (optional)
}, // pass here the same [TextEditingController] that is connected to your input field, usually a [TextFormField]
config: Config(
columns: 7,
emojiSizeMax: 32 * (Platform.isIOS ? 1.30 : 1.0), // Issue: https://github.com/flutter/flutter/issues/28894
verticalSpacing: 0,
horizontalSpacing: 0,
gridPadding: EdgeInsets.zero,
initCategory: Category.RECENT,
bgColor: Color(0xFFF2F2F2),
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentsLimit: 28,
noRecents: const Text(
'No Recents',
style: TextStyle(fontSize: 20, color: Colors.black26),
textAlign: TextAlign.center,
), // Needs to be const Widget
loadingIndicator: const SizedBox.shrink(), // Needs to be const Widget
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL,
),
);
}
}
you need to set height for your emojiSelect like this:
SizedBox(height: 300, child: emojiSelect()),
So there are multiple errors shown when you try to run your code. If you scroll to the top there are a lot of indicators that something is wrong with the height of the view.
If you check the example provided within the library, you can see that the author wrapped the EmojiPicker with SizedBox.
If you do something similar to:
child: SizedBox(height: 250, child: EmojiPicker(...),)
it should help.

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.

Is it possible to create bottom navigation bar in a stack flutter

I want to add a bottom navigation bar for my code. but don't know where to add it properly. is it possible to add it in a stack? if not how do I add a navigation bar to my code without errors? can someone please suggest to me what to do about this? here's my home.dart and bottom navigation bar code I hope to add.
home.dart
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget{
#override
_HomePageState createState() => _HomePageState();}
class _HomePageState extends State <HomePage>{
#override
Widget build (BuildContext context){
return Scaffold(
backgroundColor: Color(0xffEDEFF4),
body: Padding(
padding: const EdgeInsets.only(top: 40, left: 20, right: 20),
child: ListView (
children: [
buildSearchInput(),
Stack(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 45, 10, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Color(0xffCAEC93),
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Banana",
style: TextStyle(
fontFamily:'Roboto',
fontSize: 22,
color: Colors.black,
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
],
)
)
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/banana.png"),
),
),
],
),
Stack(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 45, 10, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Color(0xffCAEC93),
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Tangerine",
style: TextStyle(
fontFamily:'Roboto',
fontSize: 22,
color: Colors.black,
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
],
)
)
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/orange.png"),
),
),
],
),
Stack(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 45, 10, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Color(0xffCAEC93),
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Kiwi",
style: TextStyle(
fontFamily:'Roboto',
fontSize: 22,
color: Colors.black,
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
],
)
)
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/kiwi.png"),
),
),
],
),
],
),
),
);
}
Widget buildSearchInput() => Container(
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(14)),
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: Row(
children: [
Icon(
Icons.search,
size: 30,
color: Colors.grey.shade300,
),
Flexible(
child: TextField(
decoration: InputDecoration(border: InputBorder.none),
),
),
],
),
),
);
Widget buildCard()=> Container (
height: 23,
width: 90,
color: Color(0xffE6E848),
);
}
my code for bottom navigation bar
Stack(
children: [
bottomNaavigationBar:BottomNaavigationBar(
items:[
BottomNavigationBarItem(
icon:Icon(Icons.Icons.home),
backgroundColor:Colors.blue,
),
BottomNavigationBarItem(
icon:Icon(Icons.Icons.Icons.favorite),
label:'Feed'
backgroundColor:Colors.blue,
),
BottomNavigationBarItem(
icon:Icon(Icons.Icons.chat),
label:'Chat'
backgroundColor:Colors.blue,
),
BottomNavigationBarItem(
icon:Icon(Icons.Icons.person),
label:'Profile'
backgroundColor:Colors.blue,
),
),
],
),
You can add it in Scaffold, sure if you want.
Here is BottomNavBar example with PageView.
Let's define a pageController and currentTab variable for PageView inside our class,
PageController _pageController = PageController();
int _currentTab = 0;
Then we can initialize our controller for initial page.
#override
void initState() {
_pageController = PageController(initialPage: _currentTab);
super.initState();
}
Then here our view codes.
Scaffold(
drawer: const CustomDrawerWidget(),
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
child: BottomNavigationBar(
currentIndex: _currentTab,
iconSize: 24,
selectedItemColor: Theme.of(context).colorScheme.primary,
type: BottomNavigationBarType.fixed,
items: _items,
onTap: (index) {
setState(() {
_pageController.jumpToPage(index);
});
},
),
),
body: PageView(
physics: const NeverScrollableScrollPhysics(),
pageSnapping: true,
controller: _pageController,
children: _pages,
onPageChanged: (page) {
setState(() {
_currentTab = page;
});
},
),
);
BottomNavigationBar items:
const _items = [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Feed"),
BottomNavigationBarItem(icon: Icon(Icons.people), label: "Chat"),
BottomNavigationBarItem(icon: Icon(Icons.person), label: "Profile"),
];
Here is page list:
const _pages= [
FeedPage(),
ChatPage(),
ProfilePage(),
];
Scaffold has a property bottomNavigationBar
Use it like so:
Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: [],
),
...
)

icon on pressed function isnt working,whenever i click on any icon,i want to show any action there,what to do?

please help me. when ever I clicked on home icon it does not show any action however I applied on pressed function. icon on pressed function is not working, whenever I click on any icon, I want to show any action there, what to do???. I want to show any action there, what to do???. I want to show any action there, what to do???
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'screen_two.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Screens",
theme: ThemeData(primarySwatch: Colors.red),
home: LocationApp(),
);
}
}
class LocationApp extends StatefulWidget {
#override
_LocationAppState createState() => _LocationAppState();
}
class _LocationAppState extends State<LocationApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54.withOpacity(0.1),
offset: Offset(15.0, 20.0),
blurRadius: 20.0,
)
],
color: Colors.red.withOpacity(0.8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 131.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 70.0, bottom: 30.0),
child: Container(
width: 130.0,
height: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/she.png'),
fit: BoxFit.fill,
),
borderRadius:
BorderRadius.all(Radius.circular(100.0)),
border: Border.all(
color: Colors.white,
width: 4.0,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"Alisa",
style: TextStyle(fontSize: 30.0, color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"22 want | 35 done",
style: TextStyle(fontSize: 17.0, color: Colors.white),
),
),
],
),
),
),
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
children: [
CustomTile(
Icon(
Icons.chat_bubble_outline,
color: Colors.orangeAccent,
),
"Order",
() => {},
""),
CustomTile(
Icon(
Icons.trip_origin_outlined,
color: Colors.pink,
),
"Like",
() => {},
"new"),
CustomTile(
Icon(
Icons.star,
color: Colors.orange,
),
"Comment",
() {},
""),
CustomTile(
Icon(
Icons.android_rounded,
color: Colors.pink,
),
"Download",
() => {},
""),
CustomTile(
Icon(
Icons.zoom_out_sharp,
color: Colors.green,
),
"Edit", () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondscreen()));
}, ""),
],
),
),
Container(
height: 70,
color: Colors.black26.withOpacity(0.1),
),
Padding(
padding: const EdgeInsets.only(
top: 0.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.add_chart,
),
onPressed: () {},
),
Text('TIPS',
style: TextStyle(
color: Colors.orange, fontSize: 10)),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
Scaffold.of(context).openDrawer();
print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.person,
color: Colors.red),
onPressed: () {},
tooltip: '',
),
Text('Profile',
style: TextStyle(
color: Colors.red, fontSize: 10)),
],
)
],
),
)
],
),
),
)
],
),
),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'screen_two.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Screens",
theme: ThemeData(primarySwatch: Colors.red),
home: LocationApp(),
);
}
}
class LocationApp extends StatefulWidget {
#override
_LocationAppState createState() => _LocationAppState();
}
class _LocationAppState extends State<LocationApp> {
#override
Widget build(BuildContext context) {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
return Scaffold(
key:_scaffoldKey,
body: SingleChildScrollView(
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54.withOpacity(0.1),
offset: Offset(15.0, 20.0),
blurRadius: 20.0,
)
],
color: Colors.red.withOpacity(0.8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 131.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 70.0, bottom: 30.0),
child: Container(
width: 130.0,
height: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/she.png'),
fit: BoxFit.fill,
),
borderRadius:
BorderRadius.all(Radius.circular(100.0)),
border: Border.all(
color: Colors.white,
width: 4.0,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"Alisa",
style: TextStyle(fontSize: 30.0, color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"22 want | 35 done",
style: TextStyle(fontSize: 17.0, color: Colors.white),
),
),
],
),
),
),
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
children: [
CustomTile(
Icon(
Icons.chat_bubble_outline,
color: Colors.orangeAccent,
),
"Order",
() => {},
""),
CustomTile(
Icon(
Icons.trip_origin_outlined,
color: Colors.pink,
),
"Like",
() => {},
"new"),
CustomTile(
Icon(
Icons.star,
color: Colors.orange,
),
"Comment",
() {},
""),
CustomTile(
Icon(
Icons.android_rounded,
color: Colors.pink,
),
"Download",
() => {},
""),
CustomTile(
Icon(
Icons.zoom_out_sharp,
color: Colors.green,
),
"Edit", () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondscreen()));
}, ""),
],
),
),
Container(
height: 70,
color: Colors.black26.withOpacity(0.1),
),
Padding(
padding: const EdgeInsets.only(
top: 0.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.add_chart,
),
onPressed: () {},
),
Text('TIPS',
style: TextStyle(
color: Colors.orange, fontSize: 10)),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
_scaffoldKey.currentState.openDrawer(),
),print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.person,
color: Colors.red),
onPressed: () {},
tooltip: '',
),
Text('Profile',
style: TextStyle(
color: Colors.red, fontSize: 10)),
],
)
],
),
)
],
),
),
)
],
),
),
),
);
}
}
Add a scaffold key
Then use the key to open the drawer
First, check if your print msg print on the terminal or log while pressing on IconButton
Like this code,
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.home),
onPressed: () {
print('Menu Icon pressed');
},
),
The below code will help you to Open drawer,
declare and define scaffold key then also define drawer,
I hope the below code will help you, keep Fluttering :)
import 'package:flutter/material.dart';
class OpenDrawer extends StatefulWidget {
const OpenDrawer({Key key}) : super(key: key);
#override
_OpenDrawerState createState() => _OpenDrawerState();
}
class _OpenDrawerState extends State<OpenDrawer> {
GlobalKey<ScaffoldState> globalKey = GlobalKey();
#override
Widget build(BuildContext context) {
return Scaffold(
key: globalKey,
drawer: Drawer(child: YourDrawerWidget()),
body: Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
globalKey.currentState.openDrawer();
print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
);
}
}