How to fix this UI problem in my Flutter app? - flutter

Hello guys this is my first flutter app. I have to do a screen like an image below:
This is what I've got:
My problem is I couldn't display the add button over the circular container and if I change the text in a chip the other chips text changes too.
Like this:
This is my code:
Widget ExpertiseRow() {
void _addNewExpertiseRow() {
setState(() {
count = count + 1;
});
}
return new Container(
width: 170.0,
padding: new EdgeInsets.all(5.0),
child: new Column(children: <Widget>[
Chip(
onDeleted: () {
setState(() {
count = count - 1;
chips.removeAt(count + 1);
print(chips.toList());
});
},
deleteIcon: Icon(
Icons.close,
color: Colors.white,
size: 20,
),
backgroundColor: Colors.black,
avatar: Container(
width: 450,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20))),
child: IconButton(
//iconSize: 40,
icon: Icon(
Icons.add,
color: Colors.black,
size: 30,
),
onPressed: _addNewExpertiseRow)),
label: EditableText(
controller: controller,
onSubmitted: (text) {
chips.add(text);
print(chips.toList());
setState(() {
chips = chips;
});
},
focusNode: FocusNode(),
backgroundCursorColor: Colors.white,
cursorColor: Colors.white,
style: TextStyle(color: Colors.white),
),
),
new Container(
//padding: new EdgeInsets.all(10.0),
child: InkWell(
onTap: _addNewContactRow,
child: Image.asset(
'assets/images/add.png',
height: 50,
width: 50,
fit: BoxFit.cover,
)), /*IconButton(
alignment: Alignment.topCenter,
icon: Icon(
Icons.add,
color: Colors.black,
size: 30,
),
onPressed: _addNewContactRow))*/
)
]));
}
#override
Widget build(BuildContext context) {
var height =
MediaQuery.of(context).size.height - MediaQuery.of(context).padding.top;
var space = height > 650 ? kSpaceM : kSpaceS;
List<Widget> _expertises =
new List.generate(count, (int i) => ExpertiseRow());
return new Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: new AppBar(
title: new Center(
child: new Text(
"Compte Entrepreneur",
style: TextStyle(
fontSize: 25.0,
color: Colors.black,
),
)),
elevation: 0.0,
backgroundColor: Colors.white,
),
body: Form(
key: _formKey,
child: new LayoutBuilder(builder: (context, constraint) {
return new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 40,
),
new Text(
"Nom et prénom",
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
FadeSlideTransition(
animation: _formElementAnimation,
additionalOffset: space,
child: CustomInputField(
label: 'Votre nom',
prefixIcon: Icons.person,
obscureText: false,
textController: _fullnameController,
validator: ValidatorService.fullNameValidate,
onChanged: (text) {
name = text;
print(name);
},
)),
new Container(
padding: new EdgeInsets.all(30.0),
),
new Text(
"Position",
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
FadeSlideTransition(
animation: _formElementAnimation,
additionalOffset: space,
child: CustomInputField(
label: 'Position',
prefixIcon: Icons.work,
obscureText: false,
textController: _positionController,
validator: ValidatorService.positionValidate,
onChanged: (text) {
position = text;
print(position);
},
)),
new Container(
padding: new EdgeInsets.all(30.0),
),
new Text(
"Expertises",
style: TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
//the chips input
FadeSlideTransition(
animation: _formElementAnimation,
additionalOffset: space,
child: new Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.elliptical(20, 20)),
border: Border.all(
width: 3,
),
),
height: 130.0,
width: 370.0,
child: new ListView(
children: _expertises,
scrollDirection: Axis.horizontal,
),
)),
new Container(
padding: new EdgeInsets.all(55.0),
),
new Container(
width: 350,
//color: Colors.blue,
//padding: new EdgeInsets.all(10.0),
child: Row(children: <Widget>[
Container(
width: 270,
),
new Container(
width: 60,
color: Colors.black,
child: IconButton(
icon: Icon(
Icons.arrow_forward,
color: Colors.white,
size: 30,
),
onPressed: () {
if (_formKey.currentState.validate()) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => InterestsPage(),
),
);
}
}))
])),
],
),
);
})));
}
}
I also want to add the chips text to a list.
Looking forward to your help. Thanks in advance

Related

Flutter: I would like to scroll the ListView after the main SingleChildScrollView Scroll end

I have a ListView.builder wrapped with a SingleChildScrollView, and each has its scroll, so when I click at the ListView it only scroll the ListView without Scroll the SingleChildScrollView, and my ListView is dynamic so I can't use physics: const NeverScrollableScrollPhysics() because it disable my ListVeiw.builder
I want to Scroll the main screen which has some widgets and the ListView, builder in the middle and in last has a bottom
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Carrinho",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18,
fontFamily: 'Inter'),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Stack(
children: <Widget>[
Container(
width: 400,
child: Image.asset('assets/images/cover.jpg'),
),
Center(
child: Column(
children: [
SizedBox(height: 60),
Text(
"MEU CESTO",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 30,
fontFamily: 'Inter'),
),
],
),
),
],
),
Container(
height: 80,
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: sGreenColour,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
child: Container(
child: Column(
children: [
Row(children: [
Text(
"ITENS: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
Text("$itemsQtd",
style: TextStyle(color: Colors.white, fontSize: 16))
]),
Row(children: [
Text("TOTAL: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18)),
Text("$totalValue MT",
style: TextStyle(color: Colors.white, fontSize: 18))
])
],
),
),
),
Container(
height: MediaQuery.of(context).size.height,
// HERE MY ListView.buider
child: CartProducts(
cart_list: cart_list,
),
),
SizedBox(height: 40),
Container(
width: MediaQuery.of(context).size.width - 30,
child: Row(
children: [
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text("$totalValue MT",
style: TextStyle(color: sGreenColour)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
sGreenLightColour),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
),
),
),
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text(
"TERMINAR",
style: TextStyle(color: Colors.white),
),
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: sGreenColour),
),
),
),
),
)
],
),
),
SizedBox(height: 10),
],
),
));
}
}
and my ListView.builder
class _CartProductsState extends State<CartProducts> {
#override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // Disable Scroll
itemCount: widget.cart_list.length,
itemBuilder: (BuildContext context, int index) {
return SigleProduct(
name: widget.cart_list[index]["name"],
picture: widget.cart_list[index]["picture"],
price: widget.cart_list[index]["price"],
unit: widget.cart_list[index]["unit"],
);
});
}
}
// THE ELEMENT OF THE GRIDVIEW
class SigleProduct extends StatelessWidget {
SigleProduct({this.name, this.picture, this.price, this.unit})
: super(key: null);
final name;
final picture;
final price;
final unit;
showAlertDialog(BuildContext context, int id) {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("Não"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
);
Widget continueButton = TextButton(
child: Text(
"Sim",
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Producto Removido!"),
));
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Center(child: Text("Alerta!")),
content: Text("Gostaria de Remover o producto do carrinho?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
#override
Widget build(BuildContext context) {
return Container(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: ListTile(
onTap: () {},
leading: Container(
width: 80,
//color: Colors.amber,
child: Image.asset(picture),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(name,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 14)),
Text("$price MT",
style: TextStyle(
fontWeight: FontWeight.bold,
color: sGreenColour,
fontSize: 14)),
],
),
subtitle: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Unit: $price MT/$unit',
style: TextStyle(color: Colors.black45)),
Text('Qtd: 2/$unit', style: TextStyle(color: Colors.black45)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {
showAlertDialog(context, 1);
},
child: Text(
"REMOVER",
style: TextStyle(fontSize: 10, color: Colors.white),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red)),
),
),
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {},
child: Text("ACTUALIZAR",
style:
TextStyle(fontSize: 10, color: Colors.white))),
),
],
)
],
),
selected: false,
),
),
);
}
}
Please Help

How to make container fixed. the container wont resize after clicking the widgets inside it . Flutter

I am having trouble with my design as i want this container as a background for my dropdowns and textformfield. but its changing its size once i click on description or dates.
Please help how to make it fixed. i have attached some screenshots also of before and after clicking the formfield.
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
// color: Colors.white,
padding: const EdgeInsets.all(32.5),
constraints: const BoxConstraints(
minWidth: 0, maxWidth: 350, minHeight: 0, maxHeight: 440),
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
height: 52,
width: 270,
padding: const EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: const Text('Select Chapter'),
items: chapteritemlist.map((item) {
return DropdownMenuItem(
value: item['chapterId'].toString(),
child: Text(item['chapter'].toString()),
);
}).toList(),
onChanged: (newVal) {
setState(() {
dropdownchapterdisplay = newVal;
});
chaptid = newVal;
print(chaptid);
getAllMember();
},
value: dropdownchapterdisplay,
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
height: 52,
width: 270,
padding: EdgeInsets.symmetric(horizontal: 0),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: const Text('Select Member'),
items: memberitemlist.map((item) {
return DropdownMenuItem(
value: item['id'].toString(),
child: Text(
item['name'].toString(),
style: const TextStyle(
fontSize: 9,
),
),
);
}).toList(),
onChanged: (newVal) {
setState(() {
dropdownmemberdisplay = newVal;
});
memberid = newVal;
},
value: dropdownmemberdisplay,
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox(
height: 48,
width: 270,
child: TextFormField(
// The validator receives the text that the user has entered.
// textAlign: TextAlign.center,
controller: description,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
hintText: "Description",
filled: true,
fillColor: Colors.grey[200],
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox(
height: 88,
width: 270,
child: DateTimeFormField(
decoration: InputDecoration(
hintStyle: const TextStyle(color: Colors.black),
errorStyle: const TextStyle(color: Colors.redAccent),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
hintText: 'MM DD, YYYY',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: const Icon(Icons.event_note),
labelText: 'Select Date',
),
mode: DateTimeFieldPickerMode.date,
autovalidateMode: AutovalidateMode.always,
validator: (e) => (e?.day ?? 0) == 1
? 'Please not the first day'
: null,
onDateSelected: (DateTime value) {},
),
),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.all(6.0),
child: Align(
alignment: Alignment.bottomLeft,
child: ElevatedButton(
onPressed: () {
saveRequestModel = SaveClass();
saveRequestModel.Description = description.text;
saveRequestModel.UserName = global_Email;
saveRequestModel.Id = 0;
saveRequestModel.toFId = 0;
saveRequestModel.ToSelf = 0;
saveRequestModel.TranType = 0;
saveRequestModel.ToId = 6;
saveRequestModel.MeetingDate = '2022-10-02';
print(saveRequestModel.ToId);
SaveService saveService = SaveService();
saveService.save(saveRequestModel).then((value) {
print("data saved");
});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple[900],
textStyle: const TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
),
// color: Colors.deepPurple[900],
// textColor: Colors.white,
// elevation: 5,
child: const Text('Save',
style: TextStyle(fontSize: 20)),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Align(
alignment: Alignment.bottomRight,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple[900],
textStyle: const TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
),
// color: Colors.deepPurple[900],
// textColor: Colors.white,
// elevation: 5,
child: const Text('Check Report',
style: TextStyle(fontSize: 20)),
),
))
]),
),
],
)),
Here is the full code.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:date_field/date_field.dart';
//import 'package:saarthi/api/saarthi_meeting/chapter_api.dart';
import 'package:saarthi/api/saarthi_meeting/sarthi_services.dart';
import 'package:http/http.dart' as http;
import 'package:saarthi/api/saarthi_meeting/save_button.dart';
import 'package:saarthi/model/saarthi_meeting/saarthi_model.dart';
import 'package:saarthi/model/saarthi_meeting/save_model.dart';
import 'package:saarthi/variables.dart';
void main() {
runApp(Saarthi_Meeting());
}
class Saarthi_Meeting extends StatelessWidget {
Saarthi_Meeting({Key? key}) : super(key: key);
String value = "";
String url = '';
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: datadisplay(),
debugShowCheckedModeBanner: false,
);
}
}
class datadisplay extends StatefulWidget {
const datadisplay({Key? key}) : super(key: key);
#override
State<datadisplay> createState() => _datadisplayState();
}
class _datadisplayState extends State<datadisplay> {
final SaarthiService _fetchdata = SaarthiService();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple[900],
appBar: AppBar(
title: Image.asset('assets/images/CG.png', width: 200),
backgroundColor: Colors.deepPurple[900],
elevation: 13,
actions: [
IconButton(
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => smdesign()));
},
icon: const Icon(Icons.add),
)
],
),
body: Container(
padding: const EdgeInsets.all(20),
child: FutureBuilder<List<Saarthidata>>(
future: _fetchdata.smdata(),
builder: (context, snapshot) {
var data = snapshot.data;
return ListView.builder(
itemCount: data?.length,
itemBuilder: (context, index) {
if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator());
}
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListTile(
onTap: () {
if (data?[index].id != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => smdesign(),
),
);
}
},
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'On Date - ${data?[index].date}',
style: const TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
Text(
'From User - ${data?[index].fromName}',
style: const TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
Text(
'To User - ${data?[index].toName}',
style: const TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
]),
),
),
);
});
}),
),
);
}
}
class smdesign extends StatefulWidget {
smdesign({Key? key}) : super(key: key);
#override
State<smdesign> createState() => _smdesignState();
}
class _smdesignState extends State<smdesign> {
String? dropdownvalue = "Self";
String chaptervalue = "One";
bool isVisible = false;
//---------------------variable----------------------------------------------------API
List chapteritemlist = [];
var dropdownchapterdisplay;
//---------------------variable----------------------------------------------------API
List memberitemlist = [];
var dropdownmemberdisplay;
//------------------------------api dropdown 3 ---------------------------------
//--------------------------------------------------------------------------API
//----------------------------------save-------------------save--------------------------
late SaveClass saveRequestModel;
var description = TextEditingController();
//----------------------------------save-------------------save--------------------------
#override
void initState() {
super.initState();
getAllChapter();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple[900],
appBar: AppBar(
title: Image.asset('assets/images/CG.png', width: 200),
backgroundColor: Colors.deepPurple[900],
elevation: 13,
),
body: Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
// color: Colors.white,
padding: const EdgeInsets.all(32.5),
constraints: const BoxConstraints(
minWidth: 0, maxWidth: 350, minHeight: 0, maxHeight: 440),
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
height: 52,
width: 270,
padding: const EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: const Text('Select Chapter'),
items: chapteritemlist.map((item) {
return DropdownMenuItem(
value: item['chapterId'].toString(),
child: Text(item['chapter'].toString()),
);
}).toList(),
onChanged: (newVal) {
setState(() {
dropdownchapterdisplay = newVal;
});
chaptid = newVal;
print(chaptid);
getAllMember();
},
value: dropdownchapterdisplay,
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
height: 52,
width: 270,
padding: EdgeInsets.symmetric(horizontal: 0),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(20.0),
border: Border.all(
// color: Colors.black,
style: BorderStyle.solid,
width: 1.0),
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: const Text('Select Member'),
items: memberitemlist.map((item) {
return DropdownMenuItem(
value: item['id'].toString(),
child: Text(
item['name'].toString(),
style: const TextStyle(
fontSize: 9,
),
),
);
}).toList(),
onChanged: (newVal) {
setState(() {
dropdownmemberdisplay = newVal;
});
memberid = newVal;
},
value: dropdownmemberdisplay,
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox(
height: 48,
width: 270,
child: TextFormField(
// The validator receives the text that the user has entered.
// textAlign: TextAlign.center,
controller: description,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
hintText: "Description",
filled: true,
fillColor: Colors.grey[200],
),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox(
height: 88,
width: 270,
child: DateTimeFormField(
decoration: InputDecoration(
hintStyle: const TextStyle(color: Colors.black),
errorStyle: const TextStyle(color: Colors.redAccent),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
hintText: 'MM DD, YYYY',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: const Icon(Icons.event_note),
labelText: 'Select Date',
),
mode: DateTimeFieldPickerMode.date,
autovalidateMode: AutovalidateMode.always,
validator: (e) => (e?.day ?? 0) == 1
? 'Please not the first day'
: null,
onDateSelected: (DateTime value) {},
),
),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.all(6.0),
child: Align(
alignment: Alignment.bottomLeft,
child: ElevatedButton(
onPressed: () {
saveRequestModel = SaveClass();
saveRequestModel.Description = description.text;
saveRequestModel.UserName = global_Email;
saveRequestModel.Id = 0;
saveRequestModel.toFId = 0;
saveRequestModel.ToSelf = 0;
saveRequestModel.TranType = 0;
saveRequestModel.ToId = 6;
saveRequestModel.MeetingDate = '2022-10-02';
print(saveRequestModel.ToId);
SaveService saveService = SaveService();
saveService.save(saveRequestModel).then((value) {
print("data saved");
});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple[900],
textStyle: const TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
),
// color: Colors.deepPurple[900],
// textColor: Colors.white,
// elevation: 5,
child: const Text('Save',
style: TextStyle(fontSize: 20)),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20),
child: Align(
alignment: Alignment.bottomRight,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple[900],
textStyle: const TextStyle(
color: Colors.white,
font size: 25,
fontStyle: FontStyle.normal),
),
// color: Colors.deepPurple[900],
// textColor: Colors.white,
// elevation: 5,
child: const Text('Check Report',
style: TextStyle(fontSize: 20)),
),
))
]),
),
],
)),
),
);
}
}
Before Image -This is before clicking anything. The design
After Image -when I click on the description form field it shows like this.

How to make value stay despite leaving the page?

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;
},
);
}
}

how to validate entered password and confirm password are same in flutter

I am trying to validate the values of password field and confirm password field.
how to validate entered password and confirm password are same in flutter.
The edited text value could not be taken as value so couldn't find the solution.
import 'package:flutter/material.dart';
import 'package:form_field_validator/form_field_validator.dart';
import 'package:loginform_validation_demo/LoginFormWithValidation.dart';
import 'validation.dart';
import 'HomePage.dart';
class SignupPage extends StatelessWidget {
GlobalKey<FormState> formkey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
brightness: Brightness.light,
backgroundColor: Colors.white,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
size: 20,
color: Colors.black,
)),
),
body: SafeArea(
child: Form(
autovalidateMode: AutovalidateMode.always,
key: formkey,
child: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 40,
),
Text(
"Sign up",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 20,
),
Text(
"Create an Account,Its free",
style: TextStyle(
fontSize: 15,
color: Colors.grey[700],
),
),
SizedBox(
height: 30,
)
],
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
children: [
usernameMakeInput(label: "User Name"),
passwordMakeInput(label: "Password", obsureText: true),
passwordMakeInput(label: "Confirm Password", obsureText: true)
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Container(
height: 50,
width: 200,
child: MaterialButton(
minWidth: double.infinity,
height: 50,
onPressed: () {
if (formkey.currentState.validate()) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => HomePage()));
print("Validated");
} else {
print("Not Validated");
}
},
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Sign Up",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: Colors.white),
),
),
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Already have an account?",
style: TextStyle(fontSize: 15),
),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
LoginFormValidation()),
);
},
child: Text(
'Login',
style:
TextStyle(color: Colors.blue, fontSize: 18),
),
),
],
)
],
),
],
),
),
),
),
),
);
}
}
validation:
This is the part where I try to pass the edit text value
Widget passwordMakeInput({label, obsureText = false}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w400, color: Colors.black87),
),
SizedBox(
height: 5,
),
TextFormField(
onChanged: (value){
},
maxLength: 6,
obscureText: obsureText,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
border: OutlineInputBorder(),
),
validator: MultiValidator([
RequiredValidator(errorText: "* Required"),
MinLengthValidator(6,
errorText: "Password should contain 6 characters"),
])),
SizedBox(
height: 30,
)
],
);
}

Dialog is not work properly with singlechildscrollview and soft keyboard in flutter

Dialog is not working properly with singlechildscrollview and soft keyboard in flutter.
Problems:
Dialog design is gone under the soft keyboard
Scroll is not properly working when open soft keyboard
My dialog is here:-
Future<void> ShowMessageDetail(
BuildContext context, String name, String message, String date, int id) async {
txtController.text = message;
edit = false;
return showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return AlertDialog(
contentPadding: EdgeInsets.only(left: 25, right: 25),
content: Wrap(
children: [
Column(
children: [
Container(
height: 50,
width: double.infinity,
color: Colors.blue,
child: Center(
child: Text(
"Detail",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 20),
)),
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: Row(
children: [
Text(
"Name : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(name)
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 8),
child: Row(
children: [
Text(
"Date : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(date.substring(0, 10))
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Message : ",
style: TextStyle(
color: Colors.blue,
),
),
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: edit ? Colors.blue : Colors.white,
borderRadius: BorderRadius.circular(30),
border: Border.all(color: Colors.blue, width: 2),
),
child: IconButton(
onPressed: () {
setState(() {
edit ? edit = false : edit = true;
});
},
icon: Icon(
Icons.edit_outlined,
color: edit ? Colors.white : Colors.blue,
)),
),
Container(
width: 15,
),
Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30),
),
child: IconButton(
onPressed: () {
copy(message);
},
icon: Icon(
Icons.copy,
color: Colors.white,
)),
)
],
),
],
),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 300,
),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(top: 10),
child: Container(
child: TextFormField(
controller: txtController,
textAlign: TextAlign.justify,
focusNode: contentFocus,
decoration: InputDecoration.collapsed(
hintText: 'Start typing...',
hintStyle: TextStyle(
color: Colors.grey.shade400,
fontSize: 16,
fontWeight: FontWeight.w500,
),
border: InputBorder.none,
),
enabled: edit ? true : false,
maxLines: null,
keyboardType: TextInputType.multiline,
style: TextStyle(
fontSize: 15,
height: 1.2,
),
),
),
),
),
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: edit ? true : false,
child: MaterialButton(
onPressed: () {
updateMessage(name, txtController.text.toString(), id);
},
color: Colors.blue,
child: Text(
"Update",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
Container(
width: 15,
),
MaterialButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.blue,
child: Text(
"Cancel",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
],
)
],
),
],
),
],
),
);
},
);
});
}
I use scrollController for scrolling but this does not work.
Please help me to solve my dialog design problem.
wrap your Alert Dialog with SingleChildScrollview
SingleChildScrollView(
child: AlertDialog());