move dropdwon list to cupertino picker

merge-requests/5/head
Elham Rababah 6 years ago
parent 9621f5d9b5
commit 0c23520318

@ -0,0 +1,59 @@
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param:
*@return:
*@desc: This class will contian some Function will help developer
*/
class Helpers {
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param: context, items, decKey, onSelectFun
*@return: Container Widget
*@desc: showCupertinoPicker its a general function to show cupertino picker
*/
showCupertinoPicker(context, items, decKey, onSelectFun) {
showModalBottomSheet(
context: context,
builder: (BuildContext builder) {
return Container(
height: SizeConfig.realScreenHeight * .3,
child: buildPickerItems(context, items, decKey, onSelectFun));
});
}
/*
*@author: Elham Rababah
*@Date:12/4/2020
*@param: context, List items, decKey, onSelectFun
*@return: Container widget
*@desc: buildPickerIterm this function will build the items of the cupertino
*/
buildPickerItems(context, List items, decKey, onSelectFun) {
return Container(
child: CupertinoPicker(
magnification: 1.5,
// backgroundColor: Colors.black87,
children: items.map((item) {
return Text(
'${item["$decKey"]}',
style:
TextStyle(color: Theme.of(context).primaryColor, fontSize: 20),
);
}).toList(),
itemExtent: 25, //height of each item
looping: true,
onSelectedItemChanged: (int index) {
// selectitem =index;
onSelectFun(index);
},
),
);
}
}

@ -1,3 +1,5 @@
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
@ -15,7 +17,7 @@ import '../../util/dr_app_toast_msg.dart';
DrAppSharedPreferances sharedPref = DrAppSharedPreferances();
DrAppToastMsg toastMsg = DrAppToastMsg();
Helpers helpers = Helpers();
class LoginForm extends StatefulWidget with DrAppToastMsg {
LoginForm({
Key key,
@ -27,6 +29,7 @@ class LoginForm extends StatefulWidget with DrAppToastMsg {
class _LoginFormState extends State<LoginForm> {
final loginFormKey = GlobalKey<FormState>();
var projectIdController = TextEditingController();
String _platformImei = 'Unknown';
String uniqueId = "Unknown";
var projectsList = [];
@ -119,14 +122,17 @@ class _LoginFormState extends State<LoginForm> {
userInfo.Password = value;
}),
buildSizedBox(),
DropdownButtonFormField(
value: userInfo.ProjectID,
isExpanded: false,
TextFormField(
controller: projectIdController,
onTap: () {
helpers.showCupertinoPicker(
context,projectsList, 'Desciption', onSelectProject);
},
showCursor: false,
readOnly: true,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10),
isDense: true,
prefixIcon: Image.asset('assets/images/hospital_icon.png'),
// hintText: 'Enter Password',
prefixIcon: Image.asset('assets/images/password_icon.png'),
hintText: 'Select your porject',
hintStyle:
TextStyle(fontSize: 2 * SizeConfig.textMultiplier),
enabledBorder: OutlineInputBorder(
@ -141,25 +147,13 @@ class _LoginFormState extends State<LoginForm> {
//BorderRadius.all(Radius.circular(20));
),
validator: (value) {
print(value);
if (value == null) {
return 'Please select your project';
if (value.isEmpty) {
return 'Please enter your porject';
}
return null;
},
items: projectsList.map((item) {
return DropdownMenuItem(
child: Text(
'${item['Desciption']}',
),
value: item['ID'],
);
}).toList(),
onChanged: (value) {
print(value);
setState(() {
userInfo.ProjectID = value;
});
onSaved: (value) {
userInfo.Password = value;
}),
buildSizedBox(),
Row(
@ -266,7 +260,6 @@ class _LoginFormState extends State<LoginForm> {
// save imei on shared preferance
} else {
// handel error
print('Heeeeeeeeeeeer');
showLoginError(res['ErrorEndUserMessage']);
}
}).catchError((err) {
@ -335,4 +328,12 @@ class _LoginFormState extends State<LoginForm> {
saveObjToString(String key, value) async {
sharedPref.setObj(key, value);
}
onSelectProject(index) {
setState(() {
userInfo.ProjectID = projectsList[index]["ID"];
projectIdController.text = projectsList[index]['Desciption'];
});
}
}

Loading…
Cancel
Save