Flutter Bottom Sheet and DropDownMenu Problem - flutter

I am creating a Firebase Flutter Application, in which the Bottom Sheet and DropDown Menu are conflicting
Since I wanted curved borders on the Bottom Sheet I added:
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
canvasColor: Colors.transparent,
),
Then on my home page on clicking button, on pressed function is triggered:
onPressed: () {
return showModalBottomSheet(
context: context,
builder: (context) {
return Container(
color: Colors.transparent,
child: Container(
padding:
EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
decoration: BoxDecoration(
color: Colors.purple[200],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
)
),
child: bottomSheetPanel(),
)
);
}
);
But when an option is selected from drop down menu
How do I correct it?
Any help will be much appreciated:)

i m posting the code of bottom sheet by using firebase and also have dropdown menu so you can take help from this code.
Widget updatebottomSheet()
{
Size size = MediaQuery.of(context).size;
String _dropDownValue;
String starthoour;
String endhour;
String startminute;
String endminute;
showModalBottomSheet(
enableDrag: false,
isDismissible: false,
isScrollControlled: true,
context: context,
builder:(context)
{
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom+10),
// height: size.height*0.6,
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(25.0),
child: Container(
decoration: BoxDecoration(
//color: Colors.red,
borderRadius: BorderRadius.circular(20),
),
height: size.height*0.6,
width: double.infinity,
child: Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
NameField(
controller: teacherid,
icon: Icons.person,
hintText: "Please enter Teacher id",
text: "you not enter name",
onchanged: (value)
{
Administrative.instance.addteacherId=value;
},
),
NameField(
controller:name ,
icon: Icons.meeting_room_outlined,
hintText: "Please enter room no",
text: "you not enter room no",
onchanged: (value)
{
Administrative.instance.room=value;
},
),
FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots()==null?Container():StreamBuilder(
stream:FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots(),
builder: (BuildContext context,AsyncSnapshot<QuerySnapshot>snapshot) {
var length = snapshot.data.docs.length;
// DocumentSnapshot ds = snapshot.data.docs[length];
return DropdownButton(
hint: _dropDownValue==null
? Text("Choose Section")
:Text(_dropDownValue,style: TextStyle(color: Colors.blue),),
isExpanded: true,
iconSize: 30,
items:snapshot.data.docs.map((DocumentSnapshot document)
{
return DropdownMenuItem<String>(
value: document.data()["SectionName"],
child: Text(document.data()["SectionName"]),
);
}
).toList(),
onChanged: (value){
setState(() {
_dropDownValue=value;
});
},
);
}
),
SizedBox(height: 10,),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right:8.0),
child: Text("Lecture Start time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.only(right:20.0),
child: DropdownButton(
hint: starthoour == null
? Text('Choose')
: Text(
starthoour,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
starthoour = val;
},
);
},
),
),
DropdownButton(
hint: startminute == null
? Text('Choose')
: Text(
startminute,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['10', '20', '30',"40","50","60"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
startminute = val;
},
);
},
),
],
),
SizedBox(height: 20,),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right:8.0),
child: Text("Lecture End time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.only(right:20.0),
child: DropdownButton(
hint: endhour == null
? Text('Choose')
: Text(
endhour,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
endhour = val;
},
);
},
),
),
DropdownButton(
hint: endminute == null
? Text('Choose')
: Text(
endminute,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['10', '20', '30',"40","50","60"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
endminute = val;
},
);
},
),
],
),
],
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: () {
if(!_formKey.currentState.validate()){
return;
}
else
{
if(_dropDownValue==null||endminute==null||endhour==null||startminute==null||starthoour==null)
{
Fluttertoast.showToast(
msg: "Please choose properly from DropDown",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.redAccent,
textColor: Colors.white,
fontSize: 16.0
);
}
else
{
_formKey.currentState.validate();
addslot(_dropDownValue,starthoour,startminute,endhour,endminute);
}
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Save",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: (){
Navigator.pop(context);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Cancel",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
],
),
),
),
);
}
);
}

Related

Bloc state management with stepper widget

I am currently learning how to use the Bloc state management library in Flutter, and I have a scenario where I would like to listen to an action performed (e.g. Radio and dropDownButton).
I want to rebuild ui to with correct way to set state the new changes when press on Radio
this is code with cubit state management
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../shared/styles/colors.dart';
import '../../shared/components/components.dart';
import 'cubit/registration_cubit.dart';
class RegistrationScreen extends StatelessWidget {
const RegistrationScreen({super.key});
#override
Widget build(BuildContext context) {
bool isKeyboard = MediaQuery.of(context).viewInsets.bottom != 0;
var size = MediaQuery.of(context).size;
List<Step> getSteps() => [
Step(
state: RegistrationCubit.get(context).currentStep > 0
? StepState.complete
: StepState.indexed,
title: const Text(""),
content: Form(
key: RegistrationCubit.get(context).formKey1,
child: Column(
children: [
SizedBox(
height: 60,
child: defaultFormField(
controller:
RegistrationCubit.get(context).fullNameController,
type: TextInputType.text,
label: 'الاسم الكامل',
prefix: Icons.face,
validate: (val) {
if (val!.isEmpty) {
return 'يجب إدخال الاسم الكامل';
}
return null;
}),
),
const SizedBox(
height: 4,
),
SizedBox(
height: 60,
child: defaultFormField(
controller:
RegistrationCubit.get(context).emailController,
type: TextInputType.emailAddress,
label: 'البريد الالكتروني',
prefix: Icons.email,
validate: (val) {
if (val!.isEmpty) {
return 'يجب إدخال البريد الالكتروني';
}
return null;
}),
),
const SizedBox(
height: 4,
),
SizedBox(
height: 60,
child: defaultFormField(
controller:
RegistrationCubit.get(context).userNameController,
type: TextInputType.text,
label: 'اسم المستخدم',
prefix: Icons.person,
validate: (val) {
if (val!.isEmpty) {
return 'يجب إدخال اسم المستخدم';
}
return null;
}),
),
const SizedBox(
height: 4,
),
SizedBox(
height: 60,
child: defaultFormField(
controller:
RegistrationCubit.get(context).passwordController,
type: TextInputType.visiblePassword,
label: 'كلمة المرور',
prefix: Icons.lock,
suffix: RegistrationCubit.get(context).suffix,
isPassword: RegistrationCubit.get(context).isPassword,
suffixPressed: () {
RegistrationCubit.get(context)
.changePasswordVisibility();
},
validate: (val) {
if (val!.isEmpty) {
return 'يجب إدخال كلمة المرور';
}
return null;
}),
),
Row(
children: [
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "male",
groupValue: RegistrationCubit.get(context).sex,
onChanged: (value) {
RegistrationCubit.get(context).changeRadio(
RegistrationCubit.get(context).sex,
value.toString());
},
),
const Text(
"ذكر",
style: TextStyle(fontSize: 15),
),
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "female",
groupValue: RegistrationCubit.get(context).sex,
onChanged: (value) {
// setState(() {
// sex = value.toString();
// });
},
),
const Text(
"أنثى",
style: TextStyle(fontSize: 15),
),
const SizedBox(width: 16),
const Spacer()
],
),
],
),
),
isActive: RegistrationCubit.get(context).currentStep >= 0),
Step(
state: RegistrationCubit.get(context).currentStep > 1
? StepState.complete
: StepState.indexed,
title: const Text(""),
content: Column(
children: [
const FittedBox(
fit: BoxFit.cover,
child: Text("■ هل لديك السماحية بحجز مناوبات عمليات : ",
style: TextStyle(
color: thirdColor,
fontWeight: FontWeight.normal,
fontSize: 20))),
Row(
children: [
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "yes",
groupValue: RegistrationCubit.get(context).operations,
onChanged: (value) {
// setState(() {
// operations = value.toString();
// });
},
),
const Text(
"نعم",
style: TextStyle(fontSize: 16),
),
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "no",
groupValue: RegistrationCubit.get(context).operations,
onChanged: (value) {
// setState(() {
// operations = value.toString();
// });
},
),
const Text(
"لا",
style: TextStyle(fontSize: 16),
),
const Spacer()
],
),
const SizedBox(height: 20),
const FittedBox(
fit: BoxFit.cover,
child: Text("■ هل لديك السماحية بحجز مناوبات قائد قطاع :",
style: TextStyle(
color: thirdColor,
fontWeight: FontWeight.normal,
fontSize: 20))),
Row(
children: [
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "yes",
groupValue: RegistrationCubit.get(context).opLeader,
onChanged: (value) {
// setState(() {
// opLeader = value.toString();
// });
},
),
const Text(
"نعم",
style: TextStyle(fontSize: 16),
),
const Spacer(),
Radio(
fillColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return primaryColor;
}
return Colors.black54;
}),
value: "no",
groupValue: RegistrationCubit.get(context).opLeader,
onChanged: (value) {
// setState(() {
// opLeader = value.toString();
// });
},
),
const Text(
"لا",
style: TextStyle(fontSize: 16),
),
const Spacer()
],
),
const SizedBox(height: 20),
const FittedBox(
fit: BoxFit.cover,
child: Text(
"■ قم باختيار المركز التابع إليه والرتبة : ",
style: TextStyle(
color: thirdColor,
fontWeight: FontWeight.normal,
fontSize: 20))),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
defaultDropdownButton(
context: context,
choice: RegistrationCubit.get(context).location,
label: "المركز",
list: RegistrationCubit.get(context).locationList,
onChange: (val) {
// setState(() {
// location = val.toString();
// });
}),
const SizedBox(width: 10),
defaultDropdownButton(
context: context,
choice: RegistrationCubit.get(context).rank,
label: "الرتبة",
list: RegistrationCubit.get(context).rankList,
onChange: (val) {
// setState(() {
// rank = val.toString();
// });
}),
],
),
const SizedBox(
height: 15,
)
],
),
isActive: RegistrationCubit.get(context).currentStep >= 1),
Step(
state: RegistrationCubit.get(context).currentStep > 2
? StepState.complete
: StepState.indexed,
title: const Text(""),
content: Column(
children: <Widget>[
CircleAvatar(
radius: 50.0,
backgroundColor: Colors.transparent,
child: RegistrationCubit.get(context).imageFile == null
? Image.asset('assets/images/id.png')
: Image.file(RegistrationCubit.get(context).imageFile!),
),
const SizedBox(
height: 10.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButton(
height: 38,
fontSize: 16,
radius: 5,
width: 100,
text: "اختيار",
backgroundColor: secondaryColor,
borderColor: secondaryColor,
foregroundColor: Colors.black54,
function: () {
RegistrationCubit.get(context).getImage();
},
),
buildButton(
height: 38,
fontSize: 16,
radius: 5,
width: 100,
text: "تعليمات",
backgroundColor: secondaryColor,
borderColor: secondaryColor,
foregroundColor: Colors.black54,
function: () {},
),
],
),
const SizedBox(
height: 40.0,
),
SizedBox(
height: 60,
child: defaultFormField(
controller:
RegistrationCubit.get(context).phoneController,
type: TextInputType.phone,
label: 'رقم الموبايل',
prefix: Icons.call,
validate: (val) {
if (val!.isEmpty) {
return 'يجب إدخال رقم الموبايل';
}
return null;
})),
const SizedBox(
height: 10.0,
),
],
),
isActive: RegistrationCubit.get(context).currentStep >= 1),
];
return BlocConsumer<RegistrationCubit, RegistrationState>(
listener: (context, state) {},
builder: (context, state) {
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
backgroundColor: secondaryColor,
body: Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: size.height * 0.4,
width: size.width,
decoration: const BoxDecoration(
color: primaryColor,
borderRadius: BorderRadiusDirectional.vertical(
bottom: Radius.circular(
25.0,
),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 40, right: 10),
child: Align(
alignment: Alignment.topRight,
child: IconButton(
onPressed: () async {
FocusManager.instance.primaryFocus?.unfocus();
await Future.delayed(
const Duration(milliseconds: 100), () {
Navigator.pop(context);
});
},
icon: const Icon(
Icons.arrow_back,
size: 30,
color: Colors.white,
),
),
),
),
),
SizedBox(
height: size.height * 0.4 - 30,
child: Visibility(
visible: !isKeyboard,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 90,
width: 90,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadiusDirectional.all(
Radius.circular(
20.0,
),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/images/logo.png",
),
),
),
const Text("تسجيل إشتراك",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 22)),
],
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 100),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: !isKeyboard
? size.height * 0.4 - 175
: size.height * 0.4 - 250,
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 30),
height: 455,
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadiusDirectional.all(
Radius.circular(
25.0,
),
),
),
child: Theme(
data: ThemeData(
fontFamily: GoogleFonts.cairo().fontFamily,
primarySwatch: Colors.red,
canvasColor: Colors.transparent,
colorScheme: const ColorScheme.light(
primary: primaryColor)),
child: Stepper(
physics: const NeverScrollableScrollPhysics(),
type: StepperType.horizontal,
elevation: 0,
steps: getSteps(),
currentStep:
RegistrationCubit.get(context).currentStep,
controlsBuilder: (BuildContext context,
ControlsDetails controls) {
final isLastStep =
RegistrationCubit.get(context)
.currentStep ==
getSteps().length - 1;
return Row(
children: <Widget>[
Expanded(
child: buildButton(
height: 38,
fontSize: 16,
radius: 5,
width: size.width,
text:
isLastStep ? "تأكيد" : "التالي",
backgroundColor: primaryColor,
borderColor: primaryColor,
foregroundColor: Colors.white,
function: () {
if (isLastStep) {
} else {
RegistrationCubit.get(context)
.changeCurrentStep(1);
}
}),
),
if (RegistrationCubit.get(context)
.currentStep !=
0)
const SizedBox(width: 12),
if (RegistrationCubit.get(context)
.currentStep !=
0)
Expanded(
child: buildButton(
height: 38,
fontSize: 16,
radius: 5,
width: size.width,
text: "رجوع",
backgroundColor: secondaryColor,
borderColor: secondaryColor,
foregroundColor: Colors.black54,
function: () {
if (RegistrationCubit.get(context)
.currentStep !=
0) {
RegistrationCubit.get(context)
.changeCurrentStep(-1);
}
},
),
),
],
);
},
),
)),
const SizedBox(
height: 30,
)
],
),
),
),
],
),
),
);
},
);
}
}

Bottom Overflows by 121 pixels after my phone's on screen keyboard shows up for searching Match Lobbies in Filter Feature

I am trying to implement a Filter Feature for my Match Lobbies, but the thing is as soon as I try to search any lobbies in the CustomTextField, my phone's on-screen keyboard shows up which makes my Bottom Overflow by 121 pixels.
I am posting a screenshot of the Filter Feature before and after the overflow to have a clear idea.
Please ignore the Circular Logo Error in the photo, that is just the logo display error due to the path not provided.
Code:
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: BottomSheet(
onClosing: () => {},
builder: (_) {
return SizedBox(
height: 595.h,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15.w),
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
padding: EdgeInsets.only(
top: 34.h,
left: 40.w,
),
child: Text(
'Filter',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontSize: 28.sp,
fontWeight: FontWeight.w600,
),
),
),
),
Container(
decoration: BoxDecoration(
color: const Color(0xFF2B2B3D),
borderRadius: BorderRadius.circular(
10.r,
),
),
child: CustomTextField(
hintText: 'Host Username',
controller: _controller,
onChanged: (p0) => print(p0),
),
),
SizedBox(
height: 12.h,
),
Container(
height: 150.h,
decoration: BoxDecoration(
color: const Color(0xFF2B2B3D),
borderRadius: BorderRadius.circular(
10.r,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: ListView(
scrollDirection: Axis.horizontal,
children: [
SizedBox(
width: 200.w,
child: RadioListTile<String>(
activeColor: Colors.white,
title: Text(
"By Team",
style: Theme.of(context).textTheme.bodyMedium,
),
value: "team",
groupValue: selectedMatchFilter,
onChanged: (String? value) => setState(() {
selectedMatchFilter = value;
}),
),
),
SizedBox(
width: 200.w,
child: RadioListTile<String>(
activeColor: Colors.white,
title: Text(
"By League",
style: Theme.of(context).textTheme.bodyMedium,
),
value: "league",
groupValue: selectedMatchFilter,
onChanged: (String? value) => setState(() {
selectedMatchFilter = value;
}),
),
),
],
),
),
SizedBox(
height: 100.h,
child: Row(
children: [
Expanded(
child: ListView.builder(
itemCount: 10,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => SizedBox(
height: 100.h,
width: 125.w,
child: TeamLogo(
id: 1,
imgPath: "Barcelona",
teamName: "Barcelona",
selected: false,
notifyParent: () {},
),
),
),
),
],
),
),
],
),
),
Container(
padding: EdgeInsets.only(top: 5.h),
child: const Text(
"Matchday",
textAlign: TextAlign.center,
),
),
Column(
children: [
RadioListTile<DateTime>(
activeColor: Colors.white,
title: Text(
"Today",
style: Theme.of(context).textTheme.bodyMedium,
),
value: widget.today,
groupValue: selectedMatchDateFilter,
onChanged: (DateTime? value) => setState(() {
selectedMatchDateFilter = value;
}),
),
RadioListTile<DateTime>(
activeColor: Colors.white,
title: Text(
"Tomorrow",
style: Theme.of(context).textTheme.bodyMedium,
),
value: DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1),
groupValue: selectedMatchDateFilter,
onChanged: (DateTime? value) => setState(() {
selectedMatchDateFilter = value;
}),
),
RadioListTile<DateTime>(
activeColor: Colors.white,
title: Row(
children: [
DropdownButton2<String>(
isExpanded: true,
buttonHeight: 30.h,
buttonWidth: 220.w,
items: const [
DropdownMenuItem<String>(
value: "",
child: Text("Till Date"),
),
DropdownMenuItem<String>(
value: "",
child: Text("Precise Date"),
),
],
),
1 == 2
? Checkbox(
value: true,
onChanged: (bool? _value) {},
)
: IconButton(
icon: const Icon(Icons.calendar_today),
onPressed: () => showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2022, 11, 16),
lastDate: DateTime(2023, 1, 1),
),
),
],
),
value: DateTime.now(),
groupValue: selectedMatchDateFilter,
onChanged: (value) {},
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Premium"),
Switch(
onChanged: (bool? s) => setState(() {
isPremiumFilter = s ?? false;
}),
value: isPremiumFilter,
activeColor: const Color(0xFF182A54),
inactiveThumbColor: Colors.white,
activeTrackColor: const Color(0xFFD9D9D9),
inactiveTrackColor: const Color(0xFFD9D9D9),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
onPressed: () {},
child: const Text("Apply"),
),
TextButton(
onPressed: () {},
child: const Text("Clear All"),
),
],
),
],
),
),
);
},
),
);
}
you can also wrap your widget with the following to force a full screen constrains on it, and make it scrollable:
SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
child: /*your widgets*/,
),
)
A quick fix for your case.
Add the resizeToAvoidBottomInset property in your Scaffold like this:
Scaffold(
resizeToAvoidBottomInset: true,
/*...*/
);

floatingactionbutton.extended display issues flutter

When the keyboard appears the fab is placed in the middle of the screen instead of staying on board the keyboard
There is a lot of post on this subject on the web, but I cannot find the adequate solution to mine.
Here is the code.
Widget build(BuildContext context) {
final isKeyboard = MediaQuery.of(context).viewInsets.bottom != 0;
return Scaffold(
backgroundColor: backgroundColor,
appBar: AppBar(
iconTheme: const IconThemeData(color: Colors.black),
backgroundColor: Colors.transparent,
//****************************** EDITBUTTON ***************************** */
elevation: 0,
actions: [
IconButton(
onPressed: () async {
await Databahelper.instance.deleteNote(widget.note!.id!);
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const StickyNote()));
},
icon: const Icon(Icons.delete)),
//*************************** DELETE_BUTTON ***************************** */
],
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
const SizedBox(height: 8),
TextField(
maxLines: 1,
controller: titleController,
decoration: const InputDecoration(
label: Text(
'Title',
style: TextStyle(fontSize: 20),
),
),
),
const SizedBox(
height: 30,
),
Expanded(
child: TextField(
keyboardType: TextInputType.multiline,
controller: descController,
maxLines: null,
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.all(10),
hintText: "Enter Your Text...",
hintStyle: TextStyle(
fontSize: 12,
color: Colors.purple,
fontStyle: FontStyle.italic,
),
),
),
)
],
),
),
//---------------------------bottomNavigation --------------------------------------
bottomNavigationBar: Visibility(
visible: !isKeyboard,
child: BottomAppBar(
elevation: 4,
color: backgroundColor,
child: SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.add_box_outlined)),
const Text('July 2050'),
IconButton(
onPressed: () {}, icon: const Icon(Icons.more_vert)),
],
),
),
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
setState(() {
title = titleController.text;
description = descController.text;
});
NotedB notelocal = NotedB(title: title, description: description);
addNote(notelocal);
Navigator.push(
context, MaterialPageRoute(builder: (_) => const StickyNote()));
},
label: const Text('Save note'),
icon: const Icon(Icons.note_add_outlined),
));
}
screenshot

How to implement dropdown inside popup menu in flutter

I need a popup menu or any other way to implement layout like this in flutter. I have tried to implememnt it in popup view but I wasn't successful. Please help me with this problem.
Here is the code I have tried, implementing it using any other method also will be fine. This code gives error no material widget found, if it can be fixed it'll also be helpful for me.
void showFilter() {
showGeneralDialog(
barrierLabel: "Barrier",
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: Duration(milliseconds: 700),
context: context,
pageBuilder: (_, __, ___) {
return Align(
alignment: Alignment.center,
child: Container(
height: 300,
child: SizedBox.expand(
child:Column(
children: <Widget>[
Container(
padding: EdgeInsets.only( top: SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*6),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text("Monthly Summary", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*6, color: Colors.black87,decoration: TextDecoration.none,),),
],
)
),
Container(
padding: EdgeInsets.only(top:SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
child: Divider(
color: Colors.black87,thickness: 2.0,
),
),
Container(
padding: EdgeInsets.only(left: SizeConfig.blockSizeHorizontal*6, top: SizeConfig.blockSizeHorizontal*4),
child: Row(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Text("Year - ", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*4.5, color: Colors.black87,decoration: TextDecoration.none,),)
],
),
),
Container(
child: Row(
children: <Widget>[
Container(
child: DropdownButton(
value: _dpdValue,
underline: Container(),
isExpanded: true,
iconSize: 30.0,
items: _dropdownValues.map((val) {
return new DropdownMenuItem<String>(
value: val,
child: new Text(val),
);
}).toList(),
onChanged: (val) {
if (!mounted) return;
setState(
() {
_dpdValue = val;
},
);
},
),
)
],
),
)
],
)
)
],
)
),
margin: EdgeInsets.only(top: SizeConfig.blockSizeHorizontal*15, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(SizeConfig.blockSizeHorizontal*6),
),
),
);
},
transitionBuilder: (_, anim, __, child) {
return SlideTransition(
position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim),
child: child,
);
},
);
}
I have used an Alertdialog for this,, hope it offers insight to solving your problem,
int year = 1990;
List<String> months = ['January', 'February', 'March'];
List<String> years = [];
String option, month;
#override
void initState() {
super.initState();
for (int i = year; i < 2020; i++) {
years.add(i.toString());
}
}
Future<bool> errorDialog(context) async {
Size size = MediaQuery.of(context).size;
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
content: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Monthly Summary"),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Year-'),
Container(
width: size.width * 0.5,
decoration: BoxDecoration(
border: Border.all(
color:Colors.amber),
borderRadius:
BorderRadius.all(Radius.circular(5))),
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(10, 0, 10, 0),
filled: true,
fillColor: Colors.white,
hintText: 'Select Year',
hintStyle:
TextStyle(fontWeight: FontWeight.normal)),
value: option,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.black),
onChanged: (String newValue) {
setState(() {
option = newValue;
});
},
validator: (value) {
if (value == null) {
return "Select Year";
}
return null;
},
items: years
.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Month-'),
Container(
decoration: BoxDecoration(
border: Border.all(
color:Colors.amber),
borderRadius:
BorderRadius.all(Radius.circular(5))),
width: size.width * 0.5,
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(10, 0, 10, 0),
filled: true,
fillColor: Colors.white,
hintText: 'Select Month',
hintStyle:
TextStyle(fontWeight: FontWeight.normal)),
value: month,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.black),
onChanged: (String newValue) {
setState(() {
month = newValue;
});
},
validator: (value) {
if (value == null) {
return "Select Month";
}
return null;
},
items: months
.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(2.0))),
child: Text(
"CANCEL",
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(2.0))),
child: Text(
"SEARCH",
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
],
),
),
],
),
),
);
});
});
}

Flutter when using phone keyboard, textbox gets hidden

Im having problems with the phone keyboard getting in the way of the textbox that the user has to write in, due to that the user cant see whats hes writing, heres how it looks like
This is the screen without the keyboard
This is the screen with the keyboard
This is my current code for the textfield
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
Is there anyway to prevent this?
Thank you for your time
Edit: this is my page code with the scaffold already wrapped
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
width: double.infinity,
height: double.infinity,
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white))),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white)),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
}),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('closealert')),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
}),
],
),
],
),
),
));
});
});
Try this,
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setState) {
return WillPopScope(
onWillPop: () {
return Future.value(true);
},
child: Scaffold(
body: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraint.maxHeight,
),
child: IntrinsicHeight(
child: Container(
color: Colors.red,
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Container(height: 30),
new Text(
Translations.of(context).trans('sendmessage'),
style: TextStyle(color: Colors.white),
),
Container(
height: 30,
),
DropdownButton(
focusColor: Colors.white,
hint: new Text(
Translations.of(context).trans('sendto'),
style: TextStyle(color: Colors.white),
),
isExpanded: true,
onChanged: (value) {
setState(() => selected = value);
setState(() => toEntered = selected);
},
value: selected,
items: workers.map((worker) {
return DropdownMenuItem(
child: new Text(worker.vNome),
value: worker.vCodigo,
);
}).toList(),
),
Container(
height: 30,
),
TextFormField(
initialValue: date,
onChanged: (text) {
dateEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('date'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: hour,
onChanged: (text) {
hourEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
Translations.of(context).trans('hour'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Container(
height: 30,
),
TextFormField(
initialValue: '',
onChanged: (text) {
messageEntered = text;
},
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: Translations.of(context)
.trans('message'),
fillColor: Colors.white,
labelStyle: TextStyle(color: Colors.white),
),
),
Spacer(),
Row(
children: <Widget>[
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(Translations.of(context)
.trans('sendmessage')),
onPressed: () {
sendMessage();
},
),
Spacer(),
FlatButton(
textColor: Colors.white,
color: Colors.red[800],
child: Text(
Translations.of(context)
.trans('closealert'),
),
onPressed: () {
setState(() => selected = null);
Navigator.of(context).pop();
},
),
],
),
],
),
),
),
),
);
},
),
),
);
},
);
},
);