How to add divider to dropdown list? - flutter

I have the following dropdown:
DropdownButtonFormField(
isExpanded: true,
isDense: true,
value: dropdownValue,
icon: SvgPicture.asset(
AppImages.ic_expand_dropdown,
),
iconDisabledColor: AppColors.colorDarkGray,
iconEnabledColor: AppColors.colorDarkGray,
focusNode: widget.focusNode,
validator: widget.validator,
decoration: InputDecoration(
label: widget.widgetLabel,
labelStyle:
widget.labelStyle ?? AppTextStyles.transparentBlueDark16(),
labelText: widget.isLabelRes
? AppLocales.getTextOrNull(widget.label)
: widget.label,
fillColor: Colors.white,
filled: true,
hintText: widget.pickerPlaceholder,
hintStyle: widget.hintStyle ?? AppTextStyles.alto16(),
alignLabelWithHint: true,
errorText: widget.isErrorRes
? AppLocales.getTextOrNull(widget.error)
: widget.error,
contentPadding: const EdgeInsets.symmetric(
horizontal: 0,
vertical: 0,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
width: 1,
color:
widget.enabledBorderColor ?? AppColors.colorInputBorder,
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
width: 2,
color: widget.focusedBorderColor ?? AppColors.colorAccent,
),
),
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(
width: 2,
color: AppColors.colorError,
),
),
border: UnderlineInputBorder(
borderSide: BorderSide(
width: 1,
color: widget.borderColor ?? AppColors.colorInputBorder,
),
),
),
style: AppTextStyles.grayDark16(
fontWeight: AppFontWeight.medium,
),
onChanged: (String? newValue) {
dropdownValue = newValue;
widget.onChanged(dropdownValue!);
},
items: widget.pickerList.map<DropdownMenuItem<String>>((value) {
return DropdownMenuItem<String>(
value: value,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
child: Text(
value,
style: AppTextStyles.grayDark16(
fontWeight: AppFontWeight.medium,
),
),
),
Visibility(
child: Divider(
color: AppColors.colorEden10,
height: 2.0,
indent: 10.0,
endIndent: 10.0,
),
visible: widget.pickerList.last != value,
),
],
),
);
}).toList(),
),
I need to display the dividers between items. As I didn't find any option to add it as in List, I added the divider by creating a Column that contains Text and Divider which is shown in some cases. But the problem is that when I select the item divider is also displayed in dropdown as a result and I don't see any option to hide it here. Is there any way to add a divider without displaying it after selecting item?

To avoid selected Item Divider, we need to use selectedItemBuilder:. By default, it uses items layout.
You can use on DropdownButtonFormField like
selectedItemBuilder: (context) => widget.pickerList
.map(
(text) => Text(text),
)
.toList(),
You can set your own logic to create the UI.
And the simplified State-snippet is
late List<DropdownMenuItem<String>> menuItems = [];
#override
void initState() {
super.initState();
dropdownValue = widget.pickerList.first;
for (int i = 0; i < widget.pickerList.length; i++) {
//* on 1st index there will be no divider
i == 0
? menuItems.add(
DropdownMenuItem<String>(
child: Text(
widget.pickerList[i],
),
value: widget.pickerList[i],
),
)
: menuItems.add(
DropdownMenuItem<String>(
child: Container(
width: double.maxFinite,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(
top: 6, // adjust the way you like
),
decoration: const BoxDecoration(
border: Border(
top: BorderSide(
color: Colors.grey,
width: 2,
),
),
),
child: Text(
widget.pickerList[i],
),
),
value: widget.pickerList[i],
),
);
}
}
#override
Widget build(BuildContext context) {
return DropdownButtonFormField<String>(
isExpanded: true,
isDense: true,
value: dropdownValue,
onChanged: (String? newValue) {
// dropdownValue = newValue;
// widget.onChanged(dropdownValue!);
},
items: menuItems,
selectedItemBuilder: (context) => widget.pickerList
.map(
(text) => Text(text),
)
.toList(),
);
}

Related

How to add dropdownMenu for Phone Number

I want to add dropdownMenu like picture below:
But I still do not know how to do it.
Here is my code:
SizedBox(
width: 400,
height: 60,
child: TextField(
style: body1(color: ColorName.neutralTextPrimary),
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: ColorName.neutralTextSecondary,
),
borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorName.neutralTextSecondary,
),
),
hintText: 'Phone Number',
hintStyle: body1(color: ColorName.neutralTextSecondary),
),
),
),
use this package
it's customizable you can add your own decoration
https://pub.dev/packages/intl_phone_field
You can use row inside a container with DropdownMenu
static const List<String> codes = ['+62', '+82', '+1'];
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12), border: Border.all()),
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(4),
child: DropdownButton(
icon: const Icon(
Icons.expand_more,
),
value: _selectedIndex,
items: codes
.map((e) => DropdownMenuItem(
value: codes.indexOf(e),
child: Text(e),
))
.toList(),
onChanged: (v) {
_selectedIndex = v ?? 0;
setState(() {});
}),
),
const Padding(
padding: EdgeInsets.all(2),
child: Divider(
color: Colors.black,
thickness: 2,
),
),
Expanded(
child: TextFormField(
textAlign: TextAlign.center,
))
],
),
),
),
),

How can I clear dropdown selection?

I'm using the dropdown_button2 package on the project that I'm currently working on. Everything works fine but I need to clear the selection with a cancel button and I can't reach the selected value.
Here is my code:
final TextEditingController _searchController = TextEditingController();
bool _doctorSelection = false;
DropdownButtonHideUnderline(
child: DropdownButtonFormField2<String>(
items: _doctorList
.map((item) => DropdownMenuItem(
value: item,
child: Text(
item,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
searchController: _searchController,
searchInnerWidget: TextFormField(
controller: _searchController,
textAlignVertical: TextAlignVertical.center,
decoration: const InputDecoration(
hintText: 'Doktor Adı',
hintStyle: TextStyle(
fontSize: 14,
),
suffixIcon: Icon(Icons.search),
contentPadding: EdgeInsets.only(left: 15),
),
),
searchMatchFn: (a, searchValue) {
return a.value
.toString()
.toLowerCase()
.contains(searchValue.toLowerCase());
},
onChanged: (value) {
setState(() {
_doctorSelection = true;
});
},
onMenuStateChange: (isOpen) {
if (!isOpen) {
_searchController.clear();
}
},
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
icon: Padding(
padding: EdgeInsets.only(left: 15.0),
child: Icon(
Icons.person,
),
),
),
buttonPadding: const EdgeInsets.only(
right: 15,
),
buttonHeight: 45,
isExpanded: true,
dropdownMaxHeight: 240,
dropdownWidth: screenWidth,
dropdownDecoration: BoxDecoration(
border: Border.all(
color: Colors.grey.shade400,
),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
scrollbarAlwaysShow: true,
alignment: Alignment.centerLeft,
hint: const Text(
"Doktor Ara",
style: TextStyle(fontSize: 14, color: Colors.grey),
),
icon: _doctorSelection
? GestureDetector(
onTap: () {
setState(() {
_doctorSelection = false;
});
},
child: const Icon(
Icons.cancel,
color: Colors.red,
),
)
: Icon(
Icons.keyboard_arrow_down,
color: Colors.blueGrey[400],
),
),
)
What I want to achieve is to clear the selection with the cancel button and show the hint text again.
I tried to clear _searchController but nothing happened. My guess is, I should manipulate the value in DropdownMenuItem widget but I don't know how.

How to reduce the height of the DropDownButtonFormField so that the text inside it does not go out of the middle in flutter?

When I set a height for my container that is the parent of DropDownButtonFormField, I have no problem when the height is 55, but when the height is less (42) than a certain limit, the text inside it looks like this.
As it is clear in the picture, cat is no longer in the middle of the container.
this is my code:
Container(
alignment: Alignment.center,
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: const Color(0xFF616161),
width: 0.65,
),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
child: DropdownButtonFormField(
enableFeedback: true,
menuMaxHeight: 200,
icon: Icon(Icons.keyboard_arrow_down_rounded),
iconSize: 21,
alignment: Alignment.center,
// decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: Icon(Icons.location_on_rounded),
),
dropdownColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
elevation: 2,
// isExpanded: true,
value: cityValue,
onChanged: (String? newValue) {
setState(() {
cityValue = newValue!;
});
},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style:
TextStyle(fontSize: 15, color: Color(0xff707070)),
),
);
}).toList(),
),
),
),
The icon is in the middle but not the text.
I used Offset, but then the icon gets messed up.
The default Icon size 24, so you need minimum height 48 to view properly. It would be better not to force it have certain height.You can remove height 40 for better UX.
Now let say you like to have fixed hight, for this case, you need to maintain padding for yourself.
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 6), //this one
prefixIcon: Icon(Icons.location_on_rounded),
),
Container(
alignment: Alignment.center,
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: const Color(0xFF616161),
width: 0.65,
),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: DropdownButtonFormField(
enableFeedback: true,
menuMaxHeight: 200,
icon: Icon(Icons.keyboard_arrow_down_rounded),
iconSize: 20,
alignment: Alignment.center,
// decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 6), //this one
prefixIcon: Icon(Icons.location_on_rounded),
),
dropdownColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
elevation: 2,
onChanged: (String? newValue) {},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style:
TextStyle(fontSize: 15, color: Color(0xff707070)),
),
);
}).toList(),
),
),
),
A quick solution is adding a contentPadding to the InputDecoration.
contentPadding: EdgeInsets.symmetric(vertical: 7),
Try below code using InputDecoration
DropdownButtonFormField(
decoration: const InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(width: 1, color: Colors.grey),
),
contentPadding: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 3.0,
),
border: OutlineInputBorder(),
prefixIcon: Icon(
Icons.location_on_rounded,
color: Colors.grey,
),
),
dropdownColor: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
icon: const Icon(Icons.keyboard_arrow_down_rounded),
onChanged: (value) => {
cityValue = value!,
},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map(
(e) => DropdownMenuItem(
value: e,
child: Text(e),
),
)
.toList(),
),
Your Result Screen->

How do i return a checkbox value flutter

I am have this app that uses a checkbox to receive inputs from users, for example select a type of storage you want (NVMe, ssd, hdd etc) i want a solution that if a checkbox or multiple checkboxes are selected, it outputs their values on the summary screen.I have tried youtube tutorials, i did not quite understand them. Here is my code thanks
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:signoff_app/Screens/preview.dart';
import 'package:signoff_app/storage/store.dart';
import 'package:signoff_app/widget/textformfields.dart';
class NewSign extends StatefulWidget {
NewSign({Key? key}) : super(key: key);
#override
State<NewSign> createState() => _NewSignState();
}
class _NewSignState extends State<NewSign> {
bool ssd = false;
bool hdd = false;
bool nvme = false;
bool m2 = false;
TextEditingController pcname = new TextEditingController();
TextEditingController motherboard = new TextEditingController();
TextEditingController casing = new TextEditingController();
TextEditingController ramSize = new TextEditingController();
TextEditingController ram = new TextEditingController();
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text(
'Sign Off a Computer',
style: GoogleFonts.lato(
fontSize: 16,
fontStyle: FontStyle.normal,
),
),
),
body: Container(
width: MediaQuery.of(context).size.width,
// color: Colors.black54,
child: Stack(
children: [
Container(
//margin: EdgeInsets.fromLTRB(24, 0, 0, 24),
padding: EdgeInsets.fromLTRB(32, 64, 32, 32),
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
// color: Colors.black54,
child: Column(
children: [
Expanded(
flex: 1,
child: SizedBox(
width: 100,
height: 100,
child: Image(
fit: BoxFit.contain,
image: AssetImage("./images/udlogo.png"),
),
),
),
Expanded(
flex: 3,
child: Column(
children: [
Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: pcname,
validator: (val) {
if (val!.isEmpty) {
return "required";
}
},
decoration: InputDecoration(
labelText: 'Pc Name',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
SizedBox(
width: 24,
),
Expanded(
flex: 2,
child: TextFormField(
controller: motherboard,
decoration: InputDecoration(
labelText: 'MotherBoard',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
],
),
SizedBox(
height: 62,
),
Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
controller: ram,
validator: (val) {
if (val!.isEmpty) {
return "required";
}
},
decoration: InputDecoration(
labelText: 'Ram',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
SizedBox(
width: 24,
),
Expanded(
flex: 2,
child: TextFormField(
controller: casing,
decoration: InputDecoration(
labelText: 'Casing',
// errorText: 'please enter pc name'
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide(
color: Colors.blue,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.5,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide(
color: Colors.red,
width: 1.5,
),
),
),
),
),
],
),
SizedBox(height: 24),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Storage',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w900,
),
),
SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
//ssd checkbox
Text("SSD"),
SizedBox(width: 2),
Checkbox(
value: ssd,
onChanged: (bool? value) {
setState(() {
ssd = value!;
});
},
),
//hdd checkbox
SizedBox(width: 16),
Text("HDD"),
SizedBox(width: 2),
Checkbox(
value: hdd,
onChanged: (bool? value) {
setState(() {
hdd = value!;
});
},
),
SizedBox(width: 16),
//Nvme checkbox
Text("NVMe"),
SizedBox(width: 2),
Checkbox(
value: nvme,
onChanged: (bool? value) {
setState(() {
ssd = value!;
});
},
),
//m.2 checkbox
SizedBox(width: 16),
Text("M.2"),
SizedBox(width: 2),
Checkbox(
value: m2,
onChanged: (bool? value) {
setState(() {
m2 = value!;
});
},
),
],
),
],
),
],
),
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 45,
child: ElevatedButton(
style:
ElevatedButton.styleFrom(primary: Colors.red),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PreviewSel(pcname.text,
motherboard.text, ram.text, casing.text),
),
);
},
child: Text('Submit'),
),
),
),
),
],
),
),
],
),
),
),
);
}
}
It seems to me that you have everything to now create your Text component. You update the booleans using setState in such a way that tapping the checkbox will update the state value, allowing you to use these variables inside a Widget, which will update when one of the values changes.
final String _summary = 'ssd: $ssd, hdd: $hdd, nvme: $nvme m2: $m2';
print(_summary); // 'ssd: false, hdd: false, nvme: false, m2: false';
...
Text(_summary);

How to generate password using slider in Flutter?

I am creating a Password Manager Application and when user entering his details then I wont to show them a slider which generates a password in upper Password field. I have created a some code but i am not getting result as expected when user click on GENERATE PASSWORD the it show the following output.
Expected output:-
Here is my code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
class PasswordInput extends StatefulWidget {
#override
_PasswordInputState createState() => _PasswordInputState();
}
class _PasswordInputState extends State<PasswordInput> {
bool _obscureText = true;
int generatePasswordHelper = 0;
String _passwordStrength = "Hello";
int _currentRangeValues = 6;
void _toggle() {
setState(() {
_obscureText = !_obscureText;
});
}
Widget WebsiteName() {
return TextFormField(
textCapitalization: TextCapitalization.words,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name of website",
labelStyle: TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
),
),
),
);
}
Widget WebsiteAddress() {
return TextFormField(
keyboardType: TextInputType.url,
decoration: InputDecoration(
labelText: "Website address",
labelStyle: TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
),
),
),
);
}
Widget UserName() {
return TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "Username / Email",
labelStyle: TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
),
),
),
);
}
Widget Password() {
return TextFormField(
keyboardType: TextInputType.text,
obscureText: _obscureText,
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
),
),
suffixIcon: IconButton(
icon: Icon(
_obscureText ? Icons.visibility : Icons.visibility_off,
color: Colors.grey.shade600,
),
onPressed: _toggle,
),
),
);
}
Widget Note() {
return TextFormField(
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.sentences,
maxLines: null,
decoration: InputDecoration(
labelText: "Note",
labelStyle: TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
),
),
),
);
}
Widget GeneratePassword() {
this.generatePasswordHelper = 0;
return Container(
padding: EdgeInsets.only(left: 10),
child: RichText(
text: TextSpan(
style: TextStyle(
color: Colors.deepOrange,
),
children: <TextSpan>[
TextSpan(
text: "GENERATE PASSWORD",
recognizer: TapGestureRecognizer()
..onTap = () {
setState(() {
generatePasswordHelper = 1;
});
})
]),
),
);
}
Widget PasswordGenerator() {
return Container(
color: Colors.grey.shade200,
//height: MediaQuery.of(context).size.width / 2,
width: MediaQuery.of(context).size.width / 1.1,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.only(left: 10),
child: Text(
_passwordStrength,
),
),
IconButton(
icon: Icon(Icons.close),
onPressed: () {
setState(() {
generatePasswordHelper = 0;
});
},
),
],
),
Slider(
value: _currentRangeValues.toDouble(),
min: 0,
max: 100,
divisions: 27,
onChanged: (double newValue) {
setState(() {
_currentRangeValues = newValue.round();
});
},
semanticFormatterCallback: (double newValue) {
return '${newValue.round()} dollars';
}
)
],
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
//resizeToAvoidBottomPadding: false,
appBar: AppBar(
centerTitle: true,
title: Text("Add Password"),
),
body: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(),
child: Container(
padding: EdgeInsets.only(left: 16, right: 16),
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 20,
),
WebsiteName(),
SizedBox(
height: 20,
),
WebsiteAddress(),
SizedBox(
height: 20,
),
UserName(),
SizedBox(
height: 20,
),
Password(),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
if (generatePasswordHelper == 0)
GeneratePassword()
else
PasswordGenerator()
],
),
SizedBox(
height: 20,
),
Note(),
SizedBox(
height: 20,
),
Container(
height: 50,
width: double.infinity,
child: FlatButton(
onPressed: () {},
padding: EdgeInsets.all(0),
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xffff5f6d),
Color(0xffff5f6d),
Color(0xffffc371),
],
),
),
child: Container(
alignment: Alignment.center,
constraints: BoxConstraints(
maxWidth: double.infinity, minHeight: 50),
child: Text(
"Submit",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
),
),
],
),
),
),
),
);
}
}
You should provide an initalValue to your password field. Init a variable with a default blank value, then when you generate a password save it in that variable and use it as the password field value
https://api.flutter.dev/flutter/widgets/FormField/initialValue.html
class _PasswordInputState extends State<PasswordInput> {
bool _obscureText = true;
int generatePasswordHelper = 0;
String _passwordStrength = "Hello";
int _currentRangeValues = 6;
String currentPassword = ""
...
Widget Password() {
return TextFormField(
keyboardType: TextInputType.text,
obscureText: _obscureText,
initialValue: currentPassword
...
When you generate a password save it in currentPassword using setState