You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/ChildVaccines/add_newchild_page.dart

254 lines
9.6 KiB
Dart

4 years ago
import 'package:device_calendar/device_calendar.dart';
4 years ago
import 'package:diplomaticquarterapp/core/model/childvaccines/List_BabyInformationModel.dart';
4 years ago
import 'package:diplomaticquarterapp/core/model/childvaccines/add_newchild_model.dart';
import 'package:diplomaticquarterapp/core/model/childvaccines/create_new_user_model.dart';
4 years ago
import 'package:diplomaticquarterapp/core/model/childvaccines/user_information_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/child_vaccines/add_new_child_view_model.dart';
4 years ago
import 'package:diplomaticquarterapp/core/viewModels/child_vaccines/child_vaccines_view_model.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/Blood/new_text_Field.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/ChildVaccines/add_newchild_page.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/ChildVaccines/child_page.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/medical/active_medications/DayCheckBoxDialog.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
4 years ago
4 years ago
enum Gender { Male, Female, NON }
class AddNewChildPage extends StatefulWidget {
4 years ago
String dateAdd;
4 years ago
DateTime startDay;
DateTime endDay;
AddNewChildPage() {
4 years ago
startDay = DateTime.now();
endDay = DateTime.now();
4 years ago
}
4 years ago
@override
_AddNewChildPageState createState() => _AddNewChildPageState();
}
class _AddNewChildPageState extends State<AddNewChildPage> {
int checkedValue;
TextEditingController _firstTextController = TextEditingController();
TextEditingController _secondTextController = TextEditingController();
Gender gender = Gender.Male;
CreateNewUser_New newUserChild = CreateNewUser_New();
CreateNewBaby newChild = CreateNewBaby();
String firstName = "";
String secondName = "";
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
return BaseView<AddNewChildViewModel>(
builder: (_, model, w) => AppScaffold(
4 years ago
isShowAppBar: true,
appBarTitle: TranslationBase.of(context).vaccination,
4 years ago
body: SingleChildScrollView(
physics: ScrollPhysics(),
child: Container(
margin: EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
SizedBox(
height: 25,
4 years ago
),
Texts(TranslationBase.of(context).addInstructions),
4 years ago
SizedBox(
height: 20,
4 years ago
),
NewTextFields(
hintText: TranslationBase.of(context).firstName,
4 years ago
controller: _firstTextController,
onChanged: (value) {
setState(() {
firstName = value;
});
},
4 years ago
),
SizedBox(
height: 12,
),
NewTextFields(
hintText: TranslationBase.of(context).lastName,
4 years ago
controller: _secondTextController,
onChanged: (value) {
secondName = value;
},
4 years ago
),
SizedBox(
height: 20,
4 years ago
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
4 years ago
Text(
TranslationBase.of(context).gender + " :",
4 years ago
textAlign: TextAlign.end,
4 years ago
),
4 years ago
],
),
SizedBox(
height: 15,
),
4 years ago
Container(
height: 60,
4 years ago
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
height: 60,
color: Colors.white,
child: SecondaryButton(
textColor:
checkedValue == 1 ? Colors.white : Colors.black,
color:
checkedValue == 1 ? Colors.red : Colors.white,
label: TranslationBase.of(context).male,
onTap: () {
setState(() {
checkedValue = 1;
});
},
),
4 years ago
),
4 years ago
),
Expanded(
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
height: 60,
color: Colors.white,
child: SecondaryButton(
textColor:
checkedValue == 2 ? Colors.white : Colors.black,
color:
checkedValue == 2 ? Colors.red : Colors.white,
label: TranslationBase.of(context).female,
onTap: () {
setState(() {
checkedValue = 2;
});
},
),
4 years ago
),
)
],
4 years ago
),
4 years ago
),
SizedBox(
height: 20,
4 years ago
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
TranslationBase.of(context).dob + " :",
4 years ago
textAlign: TextAlign.end,
),
],
),
SizedBox(
height: 8,
),
4 years ago
InkWell(
onTap: () {
DatePicker.showDatePicker(
context,
4 years ago
showTitleActions: true,
4 years ago
minTime: DateTime(1, 1, 1),
4 years ago
maxTime: DateTime.now(),
4 years ago
onConfirm: (date) {
4 years ago
setState(() {
4 years ago
widget.startDay = date;
4 years ago
});
},
4 years ago
currentTime: widget.startDay,
4 years ago
);
},
child: Container(
padding: EdgeInsets.all(12),
width: double.infinity,
height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white),
child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
4 years ago
children: [
Icon(
Icons.calendar_today,
color: Colors.black,
),
SizedBox(
width: 25,
),
Expanded(child: Texts(getStartDay())),
4 years ago
],
),
4 years ago
),
),
4 years ago
SizedBox(
height: 25,
4 years ago
),
Container(
height: 60,
width: double.infinity,
child: SecondaryButton(
textColor: Colors.white,
color: Colors.grey[800],
disabled: (checkedValue == null ||
firstName.isEmpty ||
secondName.isEmpty),
label: TranslationBase.of(context).add,
onTap: () async {
newChild.babyName = _firstTextController.text +
" " +
_secondTextController.text;
newChild.gender = checkedValue.toString();
newChild.strDOB = widget.startDay.toIso8601String();
newChild.tempValue = true;
newChild.isLogin = true;
4 years ago
await model.createNewBabyOrders(newChild: newChild);
if (model.isAdded) {
AppToast.showSuccessToast(
message: TranslationBase.of(context).addedChild);
Navigator.pop(context, model.isAdded);
} else {
AppToast.showSuccessToast(message: model.error);
}
},
),
),
],
),
4 years ago
),
),
// bottomSheet:
4 years ago
),
);
}
4 years ago
4 years ago
String getStartDay() {
return "${widget.startDay.day}-${widget.startDay.month}-${widget.startDay.year}";
4 years ago
}
4 years ago
}