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,
)
],
),
),
),
],
),
),
);
},
);
}
}
Related
I was trying to show 2 dialog same time and when i open second dialog, its not focusing on the widget that was in second dialog, its focusing on the widget thats on first dialog that i have opened before.
Is this issue or am i not supposed to open 2 dialog at same time?
Here is video to the issue
Here is first dialog code
showDialog(
context: context,
builder: (_) =>
AlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
width: 16,
height: 32,
decoration: BoxDecoration(
color: AppColors.colorFFBC99,
borderRadius: BorderRadius.circular(4),
),
),
const SizedBox(
width: 16,
),
Text(
S.addaRecipe,
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
],
),
SizedBox(
width: 300,
child: Row(
children: [
Text(
S.recipeBy,
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontWeight: FontWeight.w500),
),
SizedBox(
width: 8,
),
Expanded(
child: CustomMyDropDownButton(label: 'dsfsdsf'),
),
],
),
)
],
),
content: Form(
// key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(
height: 16,
),
Text(
S.addPhotos,
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontWeight: FontWeight.w500),
),
const SizedBox(
height: 8,
),
Container(
width: double.infinity,
// height: 200,
color: Colors.white,
child: Wrap(
children: [
for (int i = 0; i < 10; i++)
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 200,
height: 200,
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
S.recipeNetworkImage,
fit: BoxFit.cover,
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade100,
borderRadius: BorderRadius.circular(8),
),
width: 200,
height: 200,
child: const Center(
child: Icon(
Icons.add,
size: 32,
),
),
),
),
),
],
),
),
const SizedBox(
height: 16,
),
CustomTextField(
showLabel: true,
// controller: textEditingController,
label: S.recipeName,
validator: (v) {
if (v!.isEmpty) {
return 'This field is required';
}
return null;
},
),
const SizedBox(
height: 16,
),
CustomTextField(
showLabel: true,
// controller: textEditingController,
label: S.description,
validator: (v) {
if (v!.isEmpty) {
return 'This field is required';
}
return null;
},
),
const SizedBox(
height: 32,
),
Row(
children: [
Text(
S.nutritionalInfo,
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontWeight: FontWeight.w500),
),
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text(
S.addNutrition,
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: const [
CustomTextField(
showLabel: true,
label: S.name,
),
CustomTextField(
showLabel: true,
label: S.value,
),
],
),
actions: [
CustomOutlinedButton(
name: S.close,
onPress: () {
context.pop();
}),
CustomElevatedButton(
name: S.add,
onPress: () {},
),
],
),
);
},
icon: const Icon(Icons.add),
)
],
),
const SizedBox(
height: 8,
),
Container(
padding: EdgeInsets.all(8),
color: Colors.grey.shade100,
child: 1 == 1
? Text(
"Nutrition Info....",
)
: Column(
children: [
for (int i = 0; i < 0; i++)
ListTile(
leading:
Icon(Icons.horizontal_split_rounded),
title: Text('Calories'),
subtitle: Text('237'),
trailing: IconButton(
onPressed: () {},
icon: Icon(Icons.delete),
),
),
],
),
),
const SizedBox(
height: 32,
),
Text(
S.steps,
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontWeight: FontWeight.w500),
),
const SizedBox(
height: 8,
),
Container(
color: AppColors.colorF4F4F4,
height: 300,
width: MediaQuery.of(context).size.width * .8,
child: HtmlEditor(
controller: HtmlEditorController(),
htmlEditorOptions: const HtmlEditorOptions(
hint: "Steps....",
),
otherOptions: const OtherOptions(
height: 400,
decoration: BoxDecoration(color: Colors.red)),
),
),
const SizedBox(
height: 32,
),
],
),
),
),
const SizedBox(
height: 32,
),
Stack(
children: [
Text(
'',
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Colors.red,
),
),
Text(
'',
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Colors.green,
),
),
],
),
],
),
),
actions: [
CustomOutlinedButton(
name: S.close,
onPress: () {
context.pop();
}),
CustomElevatedButton(
name: S.add,
onPress: () {},
),
],
);
Here is the code of second dialog show dialog
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text(
S.addNutrition,
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: const [
CustomTextField(
showLabel: true,
label: S.name,
),
CustomTextField(
showLabel: true,
label: S.value,
),
],
),
actions: [
CustomOutlinedButton(
name: S.close,
onPress: () {
context.pop();
}),
CustomElevatedButton(
name: S.add,
onPress: () {},
),
],
),
);
Here is customtextfield code
import 'package:flutter/material.dart';
class CustomTextField extends StatefulWidget {
final String? label;
final TextEditingController? controller;
final String? Function(String?)? validator;
final Function(String?)? onSaved;
final bool showLabel;
final bool enableSuggestions;
final bool autocorrect;
final TextInputType? keyBoardType;
final Function(String)? onChange;
final bool showSuffixIcon;
const CustomTextField({
Key? key,
this.label,
this.controller,
this.validator,
this.onSaved,
this.enableSuggestions = true,
this.autocorrect = true,
this.keyBoardType,
this.onChange,
this.showSuffixIcon = false,
this.showLabel = false,
}) : super(key: key);
#override
State<CustomTextField> createState() => _CustomTextFieldState();
}
class _CustomTextFieldState extends State<CustomTextField> {
final textFieldFocusNode = FocusNode();
bool _obscured = false;
#override
void initState() {
// TODO: implement initState
if (widget.showSuffixIcon) {
_obscured = true;
}
super.initState();
}
void _toggleObscured() {
setState(() {
_obscured = !_obscured;
if (textFieldFocusNode.hasPrimaryFocus)
return; // If focus is on text field, dont unfocus
textFieldFocusNode.canRequestFocus =
false; // Prevents focus if tap on eye
});
}
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
widget.showLabel
? Text(
widget.label!,
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontWeight: FontWeight.w500),
)
: const SizedBox(),
SizedBox(
height: widget.showLabel ? 8 : 0,
),
TextFormField(
controller: widget.controller,
validator: widget.validator,
onSaved: widget.onSaved,
onChanged: widget.onChange,
focusNode: textFieldFocusNode,
obscureText: _obscured,
enableSuggestions: widget.enableSuggestions,
autocorrect: widget.autocorrect,
keyboardType: widget.keyBoardType,
decoration: InputDecoration(
isDense: true,
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
borderSide: BorderSide(
color: Colors.black12,
),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
borderSide: BorderSide(
color: Colors.black12,
),
),
errorBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
borderSide: BorderSide(
color: Colors.red,
),
),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
borderSide: BorderSide(
color: Colors.black12,
),
),
labelText: widget.showLabel ? null : widget.label,
// labelStyle: CustomTextStyle.kTextStyle16400.copyWith(
// color: AppColors.textColor2,
// ),
suffixIcon: widget.showSuffixIcon
? Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 4, 0),
child: GestureDetector(
onTap: _toggleObscured,
child: Icon(
_obscured
? Icons.visibility_rounded
: Icons.visibility_off_rounded,
size: 24,
color: Colors.grey,
),
),
)
: null,
),
),
],
);
}
}
Try to add autofocus: true, on your CustomTextField. It should do handle rest I believe.
TextField(
autofocus: true,
);
I am trying to make an edit page for users to update their details. I am able to edit the details. But when I leave the page the values go back to the original value it was before editing. How do I make the value stay?
Here is how the screen looks like -
Screen Picture
I did wrap the values in set state thinking that they would remain after leaving the page but they dont.
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:my_plate/screens/home_screen.dart';
import 'package:my_plate/screens/user_guide_screen.dart';
import 'package:my_plate/widgets/app_drawer.dart';
class EditProfilePage extends StatefulWidget {
static String routeName = '/profile';
#override
_EditProfilePageState createState() => _EditProfilePageState();
}
class _EditProfilePageState extends State<EditProfilePage> {
final myController = TextEditingController();
final myController1 = TextEditingController();
String name = 'carolyn1234';
String email = 'carolyn#gmail.com';
final formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text('Profile'),
backgroundColor: Color(0xff588157),
elevation: 1,
// leading: IconButton(
// icon: Icon(
// Icons.arrow_back,
// color: Colors.white,
// ),
// onPressed: () {
// Navigator.of(context).pushNamed(MainScreen.routeName);
// },
// ),
actions: [
IconButton(
icon: Icon(Icons.library_books_outlined),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UserGuideListScreen(),
));
},
),
],
),
body: Container(
padding: EdgeInsets.only(left: 16, top: 25, right: 16),
child: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Form(
key: formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: ListView(
children: [
Text(
"Profile",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w800),
),
SizedBox(
height: 15,
),
Center(
child: Stack(
children: [
Container(
width: 130,
height: 130,
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Theme.of(context)
.scaffoldBackgroundColor),
boxShadow: [
BoxShadow(
spreadRadius: 2,
blurRadius: 10,
color: Colors.black.withOpacity(0.1),
offset: Offset(0, 10))
],
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://i.postimg.cc/gj4CDtjX/image.png",
))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 4,
color:
Theme.of(context).scaffoldBackgroundColor,
),
color: Color(0xff588157),
),
child: Icon(
Icons.edit,
color: Colors.white,
),
)),
],
),
),
SizedBox(
height: 35,
),
Text(
'User Details',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
SizedBox(height: 10),
Text('Username',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black54)),
SizedBox(height: 5),
Container(
child: Text(name),
// margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.all(10.0),
width: 2000,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueGrey)),
alignment: Alignment.topLeft,
),
SizedBox(height: 10),
Text('Email',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black54)),
SizedBox(height: 5),
Container(
child: Text(email),
// margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.all(10.0),
width: 2000,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueGrey)),
alignment: Alignment.topLeft,
),
SizedBox(
height: 35,
),
Text(
'Edit Details',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
SizedBox(
height: 15,
),
TextFormField(
controller: myController,
// initialValue: 'bla123',
// enabled: false,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
width: 0.0,
),
),
label: Text('Username',
style: TextStyle(color: Colors.black)),
),
validator: (username) {
if (username == null || username.isEmpty)
return 'Field is required.';
else if (username.length < 8)
return 'Please enter a description that is at least 8 characters.';
else
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
controller: myController1,
// initialValue: 'bla#gmail.com',
// enabled: false,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
width: 0.0,
),
),
label:
Text('Email', style: TextStyle(color: Colors.black)),
),
validator: (email) {
if (email == null || email.isEmpty)
return 'Field is required.';
String pattern = r'\w+#\w+\.\w+';
if (!RegExp(pattern).hasMatch(email))
return 'Invalid E-mail Address format.';
return null;
},
),
// DropdownButtonFormField(
// // onChanged: null,
// hint: Text('Female'),
// decoration: InputDecoration(
// label: Text('Gender'),
// ),
// items: [
// DropdownMenuItem(child: Text('Female'), value: 'female'),
// DropdownMenuItem(child: Text('Male'), value: 'male'),
// ],
// onChanged: (String? value) {},
// ),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
final isValidForm = formKey.currentState!.validate();
if (isValidForm) {
setState(() {
name = myController.text;
email = myController1.text;
});
}
setState(() {
// name = myController.text;
// email = myController1.text;
});
},
color: Color(0xff588157),
padding: EdgeInsets.symmetric(horizontal: 30),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Update Details",
style: TextStyle(
fontSize: 15,
letterSpacing: 2.2,
color: Colors.white),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
showAlertDialog();
// setState(() {
//
//
// // name = myController.text;
// // email = myController1.text;
// });
},
color: Color(0xff588157),
padding: EdgeInsets.symmetric(horizontal: 30),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Delete Account",
style: TextStyle(
fontSize: 15,
letterSpacing: 2.2,
color: Colors.white),
),
)
],
)
],
),
),
),
),
drawer: AppDrawer());
}
void showAlertDialog() {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("No", style: TextStyle(color: Color(0xff588157))),
onPressed: () {
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
child: Text("Yes", style: TextStyle(color: Color(0xff588157))),
onPressed: () {
setState(() {
name = '';
email = '';
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Account deleted successfully!'),
));
Navigator.pop(context);
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text("AlertDialog"),
content: Text("Are you sure you want to submit this form?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}
I'm trying to hide the emoji keyboard when the system keyboard shows and vice versa. What I'm currently have is when the system keyboard is opened then I click on the emoji icon, the emoji keyboard shows on top of the system keyboard like so:
I'm using the emoji_picker_flutter: ^1.1.2 package, and here is the code:
Offstage(
offstage: !emojiShowing,
child: Padding(
padding: const EdgeInsets.all(10),
child: SizedBox(
height: 250,
child: EmojiPicker(
onEmojiSelected: (Category category, Emoji emoji) {
_onEmojiSelected(emoji);
},
onBackspacePressed: _onBackspacePressed,
config: Config(
columns: 8,
// Issue: https://github.com/flutter/flutter/issues/28894
emojiSizeMax: 32 * (Platform.isIOS ? 1.30 : 1.0),
verticalSpacing: 0,
horizontalSpacing: 0,
initCategory: Category.SMILEYS,
bgColor: Theme.of(context).scaffoldBackgroundColor,
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
progressIndicatorColor: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentsLimit: 28,
noRecentsText: 'No Recents',
noRecentsStyle: const TextStyle(
fontSize: 20, color: Colors.black26),
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL)),
),
),
),
Is there any solution?
Add this :
bool emojiShowing = false;
var chatMessageController = TextEditingController();
_onEmojiSelected(Emoji emoji) {
chatMessageController
..text += emoji.emoji
..selection = TextSelection.fromPosition(
TextPosition(offset: chatMessageController.text.length));
setState(() {
_send = true;
});}
_onBackspacePressed() {
chatMessageController
..text = chatMessageController.text.characters.skipLast(1).toString()
..selection = TextSelection.fromPosition(
TextPosition(offset: chatMessageController.text.length));}
And in your body, you need to do this:
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
ChatStream(widget.chatRoomId),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
Container(
margin: EdgeInsets.only(right: 15, left: 15, top: 0,bottom: 2),
height: 60,
child: Row(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(35.0),
boxShadow: [
BoxShadow(
offset: Offset(0, 3),
blurRadius: 5,
color: Colors.grey)
],
),
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
setState(() {
emojiShowing = !emojiShowing;
});
if (emojiShowing != false) {
FocusScope.of(context).unfocus();
}
},
icon: const Icon(
Icons.face,
),
),
//IconButton(
// icon: Icon(Icons.face), onPressed: () {}),
Expanded(
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: chatMessageController,
textCapitalization: TextCapitalization.sentences,
decoration: InputDecoration.collapsed(
hintText: 'Envoyer un message...',
),
onTap: () {
if (emojiShowing != false) {
setState(() {
emojiShowing = !emojiShowing;
});
}
},
onChanged: (value){
if(value.isNotEmpty){
setState(() {
_send = true;
});
}else{
setState(() {
_send = false;
});
}
},
onSubmitted: (value){
//you can send message by pressing enter
if(value.length>0){
sendMessage();
}
},
),
),
IconButton(
icon: Icon(Icons.photo_camera),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.attach_file),
onPressed: () {},
)
],
),
),
),
_send == true
? Row(
children: [
SizedBox(width: 15),
Container(
padding: const EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor, shape: BoxShape.circle),
child: InkWell(
child: Icon(
Icons.send,
color: Colors.white,
),
onTap: sendMessage,
),
),
],
)
: Text('')
],
),
),
Offstage(
offstage: !emojiShowing,
child: SizedBox(
height: 250,
child: EmojiPicker(
onEmojiSelected: (Category category, Emoji emoji) {
_onEmojiSelected(emoji);
},
onBackspacePressed: _onBackspacePressed,
config: Config(
columns: 8,
emojiSizeMax: 28 * (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: Colors.white,
indicatorColor: Theme.of(context).primaryColor,
iconColor: Colors.grey,
iconColorSelected: Theme.of(context).primaryColor,
progressIndicatorColor: Theme.of(context).primaryColor,
backspaceColor: Theme.of(context).primaryColor,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentsLimit: 32,
noRecents: const Text(
'Pas d\'émojis récents',
style: TextStyle(fontSize: 20, color: Colors.black26),
textAlign: TextAlign.center,
),
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL,
),
),
),
)
],
),
)
),
],
),
],
),
),
I created a CheckBox list, where I get the verified value of the endpoint as false, but when changing the setstate it changes to true but then returns to false, i think FuturueBuilder rebuild CheckLists when setstate is called... But i have no idea how fix it.
e.checked is parsed ...snapshot.data!.secoes![i].checklists! .map<Widget>((e) attribute coming from the model that it receives through the api, for each checkListTile there must be a value to change in onChanged.
SingleChildScrollView newAppointmentBody() {
return SingleChildScrollView(
child: FutureBuilder<AppointmentRepository>(
future: _newReport(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
child: Form(
key: _formKey,
child: SizedBox(
child: Card(
elevation: 3,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 30),
child: Column(
children: [
Row(
children: [
const Text(
'Emissor: ',
style: TextStyle(
fontSize: 16,
),
),
Text(
'${widget.employee} ',
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.w600),
)
],
),
const SizedBox(
height: 30,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Setor do Emissor *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _status,
items: dropdownSetorEmissor,
onChanged: (String? chooseValue) {
setState(
() {
selectedSetor = chooseValue!;
_status = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Turno do Emissor *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _emissor,
items: dropdownTurnoEmissor,
onChanged: (String? chooseValue) {
setState(
() {
selectEmissor = chooseValue!;
_emissor = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Setor do risco / ocorrência *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _risco,
items: dropdownSetorRisco,
onChanged: (String? chooseValue) {
setState(
() {
selectRisco = chooseValue!;
_risco = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Local / Equipamento *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
TextFormField(
controller: _controllerLocalEquip,
maxLines: 3,
focusNode: focus,
),
const SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Fonte *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _fonte,
items: dropdownFonte,
onChanged: (String? chooseValue) {
setState(
() {
selectFonte = chooseValue!;
_fonte = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Caracterização *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _caracterizacao,
items: dropdownCaracterizacao,
onChanged: (String? chooseValue) {
setState(
() {
selectCaracterizacao = chooseValue!;
_caracterizacao = chooseValue;
if (chooseValue
.contains('Segurança do Trabalho')) {
isCheckList = true;
} else {
isCheckList ^= isCheckList;
}
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Prioridade *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _prioridade,
items: dropdownPrioridade,
onChanged: (String? chooseValue) {
setState(
() {
selectPrioridade = chooseValue!;
_prioridade = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'Reincidência *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
),
],
),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
hint: const Text(
'Moderado?',
style: TextStyle(
fontSize: 20, color: Colors.black54),
),
isExpanded: true,
value: _reincidencia,
items: dropdownReincidencia,
onChanged: (String? chooseValue) {
setState(
() {
selectReincidencia = chooseValue!;
_reincidencia = chooseValue;
},
);
},
),
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
GestureDetector(
child: const Text(
'Dicas',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700),
),
onTap: () => alertDialogShowTips(),
),
],
),
const SizedBox(
height: 15,
),
const Divider(
thickness: 2,
),
const SizedBox(
height: 15,
),
Visibility(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: 6,
itemBuilder: (context, i) {
snapshot.data!.secoes![i].checklists!.map(
(e) => setState(() => isChecked = e.checked),
);
return Column(
children: <Widget>[
Container(
width: double.infinity,
padding: const EdgeInsets.only(left: 15),
color: Colors.grey[200],
child: Row(
children: [
Text(
'${snapshot.data!.secoes![i].nome}',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold),
),
const SizedBox(
height: 30,
),
],
),
),
...snapshot.data!.secoes![i].checklists!
.map(
(e) {
return CheckboxListTile(
title: Text('${e.quesito}'),
value: e.checked,
onChanged: (value) {
setState(() {
e.checked ^= value!;
print(e.checked);
});
},
);
},
).toList(),
],
);
},
),
visible: isCheckList,
),
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
side: const BorderSide(
color: Colors.transparent),
),
),
backgroundColor:
MaterialStateProperty.all(Colors.black),
),
onPressed: () => _getFromCamera(),
child: const Text(
'Adicionar foto',
style: TextStyle(fontSize: 22),
),
),
),
const SizedBox(
height: 30,
),
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
side: const BorderSide(
color: Colors.transparent),
),
),
backgroundColor:
MaterialStateProperty.all(Colors.black),
),
onPressed: () => _getFromGalery(),
child: const Text(
'Adicionar imagem',
style: TextStyle(fontSize: 22),
),
),
),
const SizedBox(
height: 30,
),
image != null
? AnimatedOpacity(
opacity: image != null ? 1 : 0,
duration: const Duration(milliseconds: 500),
child: AspectRatio(
aspectRatio: 2 / 3,
child: image != null
? Image.file(
_image,
scale: 1,
)
: null,
),
)
: const SizedBox(),
const SizedBox(
height: 30,
),
Row(
children: const [
Text(
'Descrição da Anomalia *',
style:
TextStyle(color: Colors.grey, fontSize: 16),
)
],
),
TextFormField(
maxLines: 5,
),
const SizedBox(
height: 30,
),
Row(
children: const [
Text(
'Ação Imediata',
style:
TextStyle(color: Colors.grey, fontSize: 16),
)
],
),
TextFormField(
maxLines: 5,
),
const SizedBox(
height: 30,
),
Row(
children: const [
Text(
'Ação Sugerida',
style:
TextStyle(color: Colors.grey, fontSize: 16),
)
],
),
TextFormField(
maxLines: 5,
),
const SizedBox(
height: 45,
),
SizedBox(
height: 50,
width: double.infinity,
child: ElevatedButton(
onPressed: () {
_newReport();
},
child: const Text('SALVAR'),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.green),
),
),
),
],
),
),
),
),
),
);
}
return Container();
},
),
);
}
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),),
),
),
),
],
),
),
),
);
}
);
}