I have face a issue in flutter textfield , When I am trying to use underline property in my code - show some field good some issued.
How can I solve this issue, help me someone
Here is the issue :
This is my reuseable code :
import 'package:flutter/material.dart';
import '../../configs/appColors.dart';
class LoginSignUpFormField extends StatelessWidget {
const LoginSignUpFormField({
Key? key,
required this.labelText,
required this.icons,
this.controller,
}) : super(key: key);
final String? labelText;
final IconData icons;
final TextEditingController? controller;
#override
Widget build(BuildContext context) {
return TextField(
controller: controller,
autocorrect: true,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green),
),
// enabledBorder: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
// focusedBorder: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
// border: UnderlineInputBorder(
// borderSide: BorderSide(color: black45),
// ),
hintText: labelText,
hintStyle: TextStyle(
color: black45,
fontSize: 15,
),
prefixIcon: Icon(
icons,
color: black45,
),
),
);
}
}
This is SignUp screen Code :
import 'package:duaredoctor_app/src/configs/appColors.dart';
import 'package:duaredoctor_app/src/configs/appUtils.dart';
import 'package:duaredoctor_app/src/pages/loginPage.dart';
import 'package:duaredoctor_app/src/widgets/formField/loginSignUpForm.dart';
import 'package:duaredoctor_app/src/widgets/kText.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class RegisterPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: ListView(
// physics: NeverScrollableScrollPhysics(),
children: [
FittedBox(
child: Container(
height: Get.height,
width: Get.width,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
alignment: Alignment.center,
height: 150,
width: Get.width,
color: green50,
child: KText(
text: 'REGISTER',
color: white,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Positioned(
top: 130,
child: Container(
height: Get.height,
width: Get.width,
decoration: BoxDecoration(
color: white,
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: paddingH10V10,
child: Column(
children: [
sizeH40,
LoginSignUpFormField(
labelText: 'Full name',
icons: Icons.person_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Email',
icons: Icons.email_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Phone',
icons: Icons.call_outlined,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Password',
icons: Icons.lock_outline,
),
sizeH20,
LoginSignUpFormField(
labelText: 'Password',
icons: Icons.lock_outline,
),
sizeH30,
Container(
height: 40,
width: Get.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: greenDark,
),
child: Center(
child: KText(
text: 'Login',
fontSize: 17,
color: white,
),
),
),
sizeH30,
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
KText(
text: 'Already have an account?',
fontSize: 16,
color: black54,
),
InkWell(
onTap: () => Get.to(LoginPage()),
child: Padding(
padding: paddingH10,
child: KText(
text: 'Login',
fontWeight: FontWeight.bold,
fontSize: 17,
color:
Color.fromARGB(255, 75, 174, 255),
),
),
),
],
),
],
),
),
),
),
],
),
),
)
],
),
),
);
}
}
this is an example how to do it
TextField(
................
.....................
border: InputBorder.none,
)
make all border to InputBorder.none, that is (focusedErrorBorder,focusedBorder,enabledBorder,errorBorder,etc...)
Related
I want to achieve this type of alert dialogue. so, far I able to achieve this.
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Time'),
content:
Builder(builder: (context) {
var height = 100;
var width = 60;
return Container(
height: height - 10,
width: width - 10,
child: Row(
children: [
Expanded(
flex: 2,
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration:
const InputDecoration(
hintText: "Hour",
//helperText: 'Hour',
),
),
),
const Expanded(
child: Center(
child: Text(
":",
style: TextStyle(
fontSize: 50),
),
)),
Expanded(
flex: 2,
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration:
const InputDecoration(
hintText:
"Min",
// helperText: 'Min',
),
),
),
],
),
);
}),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
setState(() {
// codeDialog = valueText;
Navigator.pop(context);
});
},
),
],
);
});
this my code and still need lots of improvements and guide me with suitable suggestions
can anybody give me overhead on how to make it achieve the same UI as above
note: I am asking for learning purposes only and am amazed if this UI is achievable through custom.
Here is the full code solution. You just have to do little tweaking of fonts and padding stuff And of course add the functionality. I have created the UI for you.
import 'package:flutter/material.dart';
class Hello extends StatefulWidget {
const Hello({Key? key}) : super(key: key);
#override
State<Hello> createState() => _HelloState();
}
class _HelloState extends State<Hello> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
child: Text('Show Dialog'),
onPressed: () {
showDialog(
context: context,
builder: (_) => SimpleDialog(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'ENTER TIME',
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.grey,
height: 80,
width: 120,
child: TextFormField(
keyboardType: TextInputType.datetime,
showCursor: false,
initialValue: '15',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 70,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
),
),
),
Text('Hour'),
],
),
Text(
':',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 70,
),
),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.grey,
height: 80,
width: 120,
child: TextFormField(
keyboardType: TextInputType.datetime,
showCursor: false,
initialValue: '15',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 70,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
),
),
),
Text('Minute'),
],
),
],
),
),
SizedBox(
height: 40,
),
Row(
children: [
Icon(Icons.access_time_outlined),
Spacer(),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Cancel',
style: TextStyle(
color: Colors.black,
),
),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'OK',
style: TextStyle(
color: Colors.black,
),
),
),
],
),
],
),
),
],
),
);
},
),
),
);
}
}
Just do TimeObject = await showTimePicker(etc) instead of showDialog
Try this and edit for your wish
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Time'),
content: Builder(builder: (context) {
var height = 100;
var width = 60;
return Container(
height: height - 50,
width: width - 30,
child: Row(
children: [
Expanded(
flex: 2,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.circular(5),
),
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration: const InputDecoration(
hintText: "Hour",
border: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
errorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
enabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
disabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedErrorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
),
),
),
),
const Expanded(
flex: 1, child: Text(":")),
Expanded(
flex: 2,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.circular(5),
),
child: TextField(
onChanged: (value) {
setState(() {
// valueText = value;
});
},
decoration: const InputDecoration(
hintText: "Min",
border: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
errorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
enabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
disabledBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
focusedErrorBorder:
UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors
.transparent),
),
),
),
),
),
],
),
);
}),
actions: <Widget>[
ElevatedButton(
child: Text('OK'),
onPressed: () {
setState(() {
// codeDialog = valueText;
Navigator.pop(context);
});
},
),
],
);
});
Try this and keep posted.
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);
As seen in the picture, I have a text field and button placed in the same row on two lines. I am trying to design it so that each element is positioned on the same y-cord in each row (basically have them sitting at the same elevation). Currently, the LB and FT buttons and the Text that says "Inches" are sort of hovering a bit over the textfields, which is what I don't want.
this is the code for the screen:
import 'package:flutter/material.dart';
import 'package:juicefit/components/square_button.dart';
class MemberSignUpGoals extends StatefulWidget {
static String id = "MemberSignUpGoals";
#override
_MemberSignUpGoals createState() => _MemberSignUpGoals();
}
class _MemberSignUpGoals extends State<MemberSignUpGoals> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffE5DDDD),
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.pop(context);
},
),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {
},
child: Text('Next'),
)
],
backgroundColor: Color(0xff32416F),
title: Text('Member Sign Up'),
),
body: SafeArea(
child: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0, bottom: 24.0),
child: Center(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 1,
child: TextField(
decoration: InputDecoration(
focusedBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
enabledBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
hintText: 'First Name',
hintStyle: TextStyle(color: Colors.black)),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(left:10.0),
child: SquareButton(
color: Color(0xff32416F),
textColor: Colors.white,
pressed: () {
setState(() {
});
},
butName: 'LB',
buttonwidth: 50.0,
height: 37.0,
),
),
SizedBox(
width: 50.0,
)
],
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: TextField(
decoration: InputDecoration(
focusedBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
enabledBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
hintText: 'First Name',
hintStyle: TextStyle(color: Colors.black)),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(left:10.0),
child: SquareButton(
color: Color(0xff32416F),
textColor: Colors.white,
pressed: () {
setState(() {
});
},
butName: 'FT',
buttonwidth: 50.0,
height: 37.0,
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(left:10.0),
child: TextField(
decoration: InputDecoration(
focusedBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
enabledBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3.0)),
hintText: 'First Name',
hintStyle: TextStyle(color: Colors.black)),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
),
Padding(
padding: const EdgeInsets.only(left:10.0),
child: Text("inches"),
)
],
)
],
),
),
),
],
),
),
);
}
}
this is the code for the squarebutton:
import 'package:flutter/material.dart';
class SquareButton extends StatelessWidget{
final color;
final pressed;
final textColor;
final String butName;
final buttonwidth;
final height;
SquareButton({#required this.color,#required this.pressed,#required this.butName,#required this.textColor, #required this.buttonwidth,this.height});
#override
Widget build(BuildContext context){
return Padding(
padding:EdgeInsets.symmetric(vertical:10.0),
child:Material(
elevation: 5.0,
color:color,
child: Container(
width: buttonwidth,
height: height == null ? 45.0 : height ,
child: MaterialButton(
onPressed:pressed,
child:Text(
butName,
style: TextStyle(
color:textColor
),
)
),
),
)
);
}
}
set the crossAxisAlignment of both the rows to
crossAxisAlignment: CrossAxisAlignment.end,
and remove the bottom padding of your SquareButton
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
I have 2 inputs in my bottom sheet but the problem is when I am opening keyboard it's covering the whole bottom sheet and the background page is move to the upside, not the bottom sheet.
Here is my code
class _addQuestionState extends State<addQuestion> {
void _submitData(){
Navigator.of(context).pop();
}
#override
Widget build(BuildContext context) {
double stackHeight = (MediaQuery.of(context).size.height);
return Container(
color: new Color.fromRGBO(255, 0, 0, 0.5),
child: Container(
height: stackHeight * 0.4,
decoration: BoxDecoration(
color: Color(0xff404040),
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
),
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10, left: 10, right:10,
bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Would Question',
labelStyle: TextStyle(
color: Colors.blue
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
onSubmitted: (_) => _submitData(),
),
TextField(
maxLength: 56,
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
counterText: '',
labelText: 'Rather Question',
labelStyle: TextStyle(
color: Colors.red
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
onSubmitted: (_) => _submitData(),
),
SizedBox(height: stackHeight * 0.04,),
RaisedButton(onPressed: () {
_submitData();
}, child: Text('Add Question', style: TextStyle(
color: Colors.white
),),color: Theme.of(context).primaryColor,
),
],
),
),
],
),
),
),
),
);
}
}
And I am calling this like
void _startAddnewTransaction(BuildContext ctx){
showModalBottomSheet(context: ctx, builder: (_) {
return addQuestion();
});
}
Here is the image
As you can see in image 2 when keyboard open the background is moving on the upside but the bottom sheet isn't moving
use SingleChildScrollView in the root for widget tree in "build" method
like this :
#override
Widget build(BuildContext context) {
double stackHeight = (MediaQuery.of(context).size.height);
return SingleChildScrollView(
child: Container(child:....));
}