Related
I have used the bottomsheet at one of my flutter project. It works perfectly on android and IOS simulator. When I run the project on real iPhone I am facing issues. please check attached code and image.
_changePasswordBottomSheet() {
showModalBottomSheet(
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
context: context,
builder: (builder) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15),
height: 400,
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: Column(
children: [
Padding(
padding: EdgeInsets.all(12.w),
child: InkWell(
onTap: () {
NavigationService().setPopNavigator();
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
setWidth(25),
setComonText(
'CHANGE PASSWORD',
setAlignment: TextAlign.center,
style: CustomTheme().setTextStyle(
fontsize: 18.w,
weight: weight.semibold,
color: C.blackTxt),
),
Container(
height: 25.w,
width: 25.w,
decoration: BoxDecoration(
color: C.primaryGreyColor,
borderRadius: BorderRadius.circular(12.5.w),
),
child: Icon(
Icons.close,
color: C.white,
size: 16.w,
)),
],
),
),
),
setHight(25.w),
Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border.all(color: C.boxBorderColor),
borderRadius: BorderRadius.circular(5)),
child: TextFormField(
controller: editController.signupPassword,
obscureText: true,
decoration: InputDecoration(
hintText: "Passsword",
border: InputBorder.none,
hintStyle: CustomTheme().setTextStyle(
fontsize: 16.w,
weight: weight.semibold,
color: C.boxBorderColor)),
style: CustomTheme().setTextStyle(
fontsize: 16.w, weight: weight.semibold),
),
),
setHight(35.w),
Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border.all(color: C.boxBorderColor),
borderRadius: BorderRadius.circular(5)),
child: TextFormField(
controller: editController.signupNewPass,
obscureText: true,
decoration: InputDecoration(
hintText: "New Passsword",
border: InputBorder.none,
hintStyle: CustomTheme().setTextStyle(
fontsize: 16.w,
weight: weight.semibold,
color: C.boxBorderColor)),
style: CustomTheme().setTextStyle(
fontsize: 16.w, weight: weight.semibold),
),
),
setHight(10.w),
Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border.all(color: C.boxBorderColor),
borderRadius: BorderRadius.circular(5)),
child: TextFormField(
controller: editController.signupConfirmPass,
obscureText: true,
decoration: InputDecoration(
hintText: "Confirm Passsword",
border: InputBorder.none,
hintStyle: CustomTheme().setTextStyle(
fontsize: 16.w,
weight: weight.semibold,
color: C.boxBorderColor)),
style: CustomTheme().setTextStyle(
fontsize: 16.w, weight: weight.semibold),
),
),
setHight(50.w),
Row(
children: [
setWidth(20.w),
Expanded(
child: createButton(
width: setDeviceWidth() - 40.w,
text: 'CANCEL',
txtColor: C.white,
btnColour: C.primaryGreyColor,
onBtnClick: () {
editController.cancelPassword();
NavigationService().setPopNavigator();
},
fontSize: 14.w,
height: 45.w,
borderRadius: BorderRadius.circular(22.5.w)),
),
setWidth(20.w),
Expanded(
child: createButton(
width: setDeviceWidth() - 40.w,
text: 'SAVE',
txtColor: C.white,
onBtnClick: () {
editController.cancelPassword();
NavigationService().setPopNavigator();
modalBottomSheetSuccess(
'Password Saved \nSuccessfully!');
TimerUtils().startTimer(() {
NavigationService().setPopNavigator();
});
},
fontSize: 14.w,
height: 45.w,
borderRadius: BorderRadius.circular(22.5.w)),
),
setWidth(20.w),
],
)
],
)),
),
);
});
}
Attached Image is:
I'm developing a login page and splash screen for a certain application, how can I set those route to launch only once?
Stack(
fit: StackFit.loose,
children: <Widget>[
Image(
image: AssetImage('images/home.png'),
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// SizedBox(height: 20.0),
//height was 60
Column(
children: <Widget>[
SizedBox(
height: 30.0,
),
Text(
"SMART HYDROPONICS",
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 30.0,
),
CircleAvatar(
backgroundColor: Colors.white,
radius: 90.0,
child: Container(
alignment: Alignment.center,
child: CircleAvatar(
backgroundColor: Colors.green,
child: Text(
'REGISTER',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
radius: 70.0,
),
)),
],
),
SizedBox(height: 20.0),
Form(
key: _key,
autovalidate: _autovalidate,
child: Column(children: <Widget>[
TextFormField(
decoration: InputDecoration(
hintText: "Enter Name",
border: InputBorder.none,
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.nature_people,
size: 30.0,
color: Colors.black,
)),
maxLength: 25,
keyboardType: TextInputType.text,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_name = val;
},
validator: _myName,
),
SizedBox(
height: 20.0,
),
SizedBox(height: 40.0),
TextFormField(
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: "Enter Number",
border: InputBorder.none,
// contentPadding: EdgeInsets.all(0.0),
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.phone,
size: 30.0,
color: Colors.black,
)),
maxLength: 10,
maxLines: 1,
keyboardType: TextInputType.phone,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_number = val;
},
validator: _myNumber,
),
SizedBox(
height: 50.0,
),
TextFormField(
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: "Product ID",
border: InputBorder.none,
// contentPadding: EdgeInsets.all(0.0),
hintStyle: TextStyle(
color: Colors.white,
wordSpacing: 20.0,
fontWeight: FontWeight.normal,
fontSize: 18.0),
icon: Icon(
Icons.settings_brightness,
size: 30.0,
color: Colors.black,
)),
maxLength: 10,
maxLines: 1,
keyboardType: TextInputType.phone,
obscureText: false,
textAlign: TextAlign.justify,
onSaved: (val) {
_number = val;
},
validator: _productId,
),
// SizedBox(height: MediaQuery.of(context).size.height/990000 ),
RaisedButton(
onPressed: _sendToServer,
color: Colors.greenAccent,
child: Text(
"Finish",
style: TextStyle(
color: Colors.white,
),
)),
]),
),
]),
],
)
You'll want to keep persistent state (like login tokens or flags marking things as viewed/accepted) via the shared_preferences plugin or some other persistent store that's local like sqlite or a flat file.
i have an edit text and icon .. and i want a line under them .. so i added a divider after them like this:
new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Image.asset(
'assets/sa-logo.png',
width: 20.0,
height: 13.0,
),
Padding(
padding: EdgeInsets.only(left: 5.0, right: 5.0),
child: new Text(
'+966',
style: TextStyle(
fontSize: 15.0, color: Colors.grey),
),
),
new Flexible(
child: new TextField(
style: new TextStyle(
fontSize: 20.0,
color: Colors.black,
),
decoration: new InputDecoration(
border: InputBorder.none,
hintText: '5xxxxxxxx',
hintStyle: new TextStyle(
fontSize: 20.0,
),
),
keyboardType: TextInputType.number,
onChanged: (String value) {
this._data.phone = value;
setState(() {
phonelength = value.length;
done();
});
}),
),
],
),
Divider()
],
),
but the space between the line and the other widgets is big as shown:
how to make it smaller?
I just added this to the TextField:
contentPadding: EdgeInsets.symmetric(vertical: 0),
and that solved the problem.
I have a list of containers wrapped in a listview, I need to give a onTap functionality like when the user taps on the container it should give me a value of that particular container, below is my code and I tried using Inkwell function but it throws an error saying vertical portview. Help me out and thanks in advance.
dynamic _allVehiclesDataView = new ListView(
children: List.generate(this._allVehiclesData.length,
(i) => new Container(
decoration: new BoxDecoration(
border: Border(
bottom: BorderSide(width: 1.0, color: Colors.grey[300]),
),
),
padding: const EdgeInsets.all(32.0),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom:5.0),
child: Text(
this._allVehiclesData[i]["vehicle"]["registration"],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Text(
'Location :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey,
),
),
Text(
(this._allVehiclesData[i]["address"] == null ||
this._allVehiclesData[i]["address"] == 'Not determined') ?
"No data available" : ""+this._allVehiclesData[i]["address"]["LongLabel"],
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Last known update :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
Text(
(this._allVehiclesData[i]["deviceTime"]),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
this._allVehiclesData[i]["fuel"] != "null"?
new Row(
children: <Widget>[
Text(
'Fuel Level :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
new Container(
decoration: new BoxDecoration(
shape : BoxShape.circle,
border: new Border.all(
color: Colors.blue[300],
width: 5.0,
)
),
),
Text(
(this._allVehiclesData[i]["fuel"].toString()),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
],
) : Text(''),
this._allVehiclesData[i]["temperature"] != "null" ?
new Row(
children: <Widget>[
Text(
'Temp :',
style: TextStyle(
fontSize: 15.0,
color: Colors.grey[500],
),
),
new Container(
decoration: new BoxDecoration(
shape : BoxShape.circle,
border: new Border.all(
color: Colors.red[300],
width: 5.0,
)
),
),
Text(
(' '+this._allVehiclesData[i]["temperature"].toString()+' C'),
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
),
),
],
):Text(""),
],
),
),
status(i),
// new InkWell(),
],
),
),
),
);
You can use the GestureDetector for the same
Wrap your Container in a GestureDetector with an onTap callback
GestureDetector(
// When the child is tapped, do your work
onTap: () {
...
...
},
// Container
child: Container(
...
),
);
Why when I use the textAligin argument in the TextFormField widget in the following code, the keyboard gets out of work. That's mean I can't set the focus and the keyboard doesn't show.
new TextFormField(
/* textAligin: TextAlign.end, */
obscureText: obscure,
style: const TextStyle(
color: Colors.white,
),
decoration: new InputDecoration(
icon: new Icon(
icon,
color: Colors.white,
),
border: InputBorder.none,
hintText: hint,
hintStyle: const TextStyle(color: Colors.white, fontSize: 15.0),
contentPadding: const EdgeInsets.only(
top: 30.0, right: 30.0, bottom: 30.0, left: 5.0),
),
)