227 lines
8.1 KiB
Dart
227 lines
8.1 KiB
Dart
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/viewmodel/exercise_changing_view_model.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
//import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
|
|
|
|
class ExerciseNewPage extends StatefulWidget{
|
|
_ExerciseNewPageState createState() => _ExerciseNewPageState();
|
|
}
|
|
|
|
class _ExerciseNewPageState extends State {
|
|
final List excluded = [43,44];
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return Consumer<ExerciseChangingViewModel>(
|
|
builder: (context, model, child ) {
|
|
String exerciseName = "";
|
|
String customerName = "";
|
|
if ( model != null ) {
|
|
if ( model.exerciseViewModel == null ) {
|
|
model.createNewModel();
|
|
}
|
|
model.exerciseViewModel.createNew();
|
|
customerName = model != null && model.customer != null
|
|
? model.customer.name + " " +
|
|
model.customer.firstName
|
|
: "Please select a customer";
|
|
|
|
exerciseName = model != null &&
|
|
model.exerciseType != null
|
|
? model.exerciseType.name
|
|
: "Please select an exercise";
|
|
}
|
|
|
|
AppLanguage appLanguage = AppLanguage();
|
|
var date = DateTime.now();
|
|
String dateName = DateFormat(DateFormat.YEAR_MONTH_DAY, appLanguage.appLocal.toString()).format(date.toUtc()) +
|
|
" " +DateFormat(DateFormat.HOUR_MINUTE, appLanguage.appLocal.toString()).format(date.toUtc());
|
|
|
|
return Form(
|
|
key: _formKey,
|
|
autovalidate: true,
|
|
child: Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back, color: Colors.deepOrange),
|
|
onPressed: () => {
|
|
Navigator.of(context).pop()
|
|
},
|
|
),
|
|
title: Text(AppLocalizations.of(context).translate(exerciseName) + " " +
|
|
AppLocalizations.of(context).translate('Save Exercise'),
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.deepOrange)),
|
|
backgroundColor: Colors.white70,
|
|
),
|
|
body: Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_login.png'),
|
|
fit: BoxFit.cover,
|
|
//height: double.infinity,
|
|
//width: double.infinity,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child: Container(
|
|
padding: const EdgeInsets.only (top: 65, left:25, right: 100),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
columnQuantityUnit(model),
|
|
columnQuantity(model),
|
|
|
|
Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
new InkWell(
|
|
child: new Text(dateName,
|
|
style: TextStyle( fontSize: 16,color: Colors.blue)),
|
|
),
|
|
ButtonTheme(
|
|
minWidth: 30.0,
|
|
height: 30.0,
|
|
child: FlatButton(
|
|
|
|
padding: EdgeInsets.only(bottom: 0),
|
|
color: Colors.transparent,
|
|
splashColor: Colors.black26,
|
|
child: Row(
|
|
children: [
|
|
|
|
Icon(Icons.arrow_forward_ios, color: Colors.orange,)
|
|
]),
|
|
onPressed:() { print("date change");},
|
|
|
|
)),
|
|
],
|
|
),
|
|
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate('Exercise date and time'),
|
|
style: TextStyle( fontSize: 16)),
|
|
),
|
|
|
|
]),
|
|
RaisedButton(
|
|
textColor: Colors.white,
|
|
color: Colors.deepOrange,
|
|
focusColor: Colors.white,
|
|
onPressed: () =>
|
|
{
|
|
if (_formKey.currentState.validate()) {
|
|
//model = ExerciseChangingViewModel(model.exerciseViewModel),
|
|
|
|
if ( ! excluded.contains(model.exerciseType.exerciseTypeId) ) {
|
|
model.addExercise(),
|
|
},
|
|
Navigator.pop(context),
|
|
}
|
|
},
|
|
child: Text("Save", style: TextStyle(fontSize: 16),)
|
|
),
|
|
|
|
]),
|
|
)
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
Column columnQuantityUnit( ExerciseChangingViewModel model) {
|
|
Column column = Column();
|
|
if ( model.exerciseType != null && model.exerciseType.unitQuantity == "1") {
|
|
column = Column(
|
|
children: [
|
|
TextFormField(
|
|
autovalidate: true,
|
|
textAlign: TextAlign.center,
|
|
initialValue: "0",
|
|
style: TextStyle(fontSize: 30,
|
|
color: Colors.lightBlue,
|
|
fontWeight: FontWeight.bold),
|
|
validator: (input) {
|
|
return validateNumberInput(input);
|
|
},
|
|
onFieldSubmitted: (input) => {
|
|
print ("UnitQuantity value $input"),
|
|
model.exerciseViewModel.setUnitQuantity(
|
|
double.parse(input))
|
|
},
|
|
|
|
),
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate(
|
|
model.exerciseType.unitQuantityUnit),
|
|
style: TextStyle(fontSize: 16)),
|
|
),
|
|
|
|
]);
|
|
};
|
|
return column;
|
|
}
|
|
|
|
Column columnQuantity( ExerciseChangingViewModel model) {
|
|
Column column = Column();
|
|
|
|
column = Column(
|
|
children: [
|
|
TextFormField(
|
|
autovalidate: true,
|
|
textAlign: TextAlign.center,
|
|
initialValue: "0",
|
|
style: TextStyle(fontSize: 60,
|
|
color: Colors.deepOrange,
|
|
fontWeight: FontWeight.bold),
|
|
validator: (input) {
|
|
return validateNumberInput(input);
|
|
},
|
|
onFieldSubmitted: (input) =>
|
|
{
|
|
print ("Quantity value $input"),
|
|
model.exerciseViewModel.setQuantity(
|
|
double.parse(input)),
|
|
model.exerciseViewModel.setUnit(model.exerciseType.unit)
|
|
|
|
}
|
|
),
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate(model.exerciseType.unit),
|
|
style: TextStyle(fontSize: 16)),
|
|
),
|
|
|
|
]);
|
|
|
|
return column;
|
|
}
|
|
|
|
String validateNumberInput( input ) {
|
|
String error = AppLocalizations.of(context).translate("Please type the right quantity 0-10000");
|
|
dynamic rc = ( input != null && input.length > 0);
|
|
if ( ! rc ) {
|
|
return null;
|
|
}
|
|
|
|
rc = double.tryParse(input);
|
|
if ( rc == null ) {
|
|
return error;
|
|
}
|
|
|
|
if ( ! ( double.parse(input) < 10000 && double.parse(input) > 0) ) {
|
|
return error;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|