109 lines
4.1 KiB
Dart
109 lines
4.1 KiB
Dart
import 'package:aitrainer_app/viewmodel/exercise_changing_view_model.dart';
|
|
import 'package:aitrainer_app/widgets/nav_drawer.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 _formKey = GlobalKey<FormState>();
|
|
final format = DateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ExerciseChangingViewModel model = Provider.of<ExerciseChangingViewModel>(context, listen: false);
|
|
model.createNewModel();
|
|
return Scaffold(
|
|
drawer: NavDrawer(),
|
|
appBar: AppBar(
|
|
title: Text('New exercise'),
|
|
),
|
|
body: Center(
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
children: <Widget>[
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Name',
|
|
),
|
|
readOnly: true,
|
|
initialValue: model != null && model.customer != null ? model.customer.name + " " + model.customer.firstName : "Please select a customer",
|
|
),
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Exercise',
|
|
),
|
|
readOnly: true,
|
|
initialValue: model != null && model.exerciseType != null ? model.exerciseType.name : "Please select an exercise",
|
|
),
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Quantity',
|
|
),
|
|
validator: (input) => (int.parse(input) < 1000 && int.parse(input) > 0) ?
|
|
null :
|
|
"Please type the right quantity 0-1000",
|
|
onChanged: (input) => model.exerciseViewModel.setQuantity(int.parse(input)),
|
|
),
|
|
|
|
Text('Exercise date and time'),
|
|
DateTimeField(
|
|
format: format,
|
|
initialValue: DateTime.now(),
|
|
onShowPicker: (context, currentValue) async {
|
|
final date = await showDatePicker(
|
|
context: context,
|
|
firstDate: DateTime(1900),
|
|
initialDate: DateTime.now(),
|
|
lastDate: DateTime(2100),
|
|
builder: (context, child) => Localizations.override(
|
|
context: context,
|
|
locale: Locale('hu'),
|
|
child: child,
|
|
),
|
|
);
|
|
if (date != null) {
|
|
final time = await showTimePicker(
|
|
context: context,
|
|
initialTime:
|
|
TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
|
|
builder: (context, child) => Localizations.override(
|
|
context: context,
|
|
locale: Locale('hu'),
|
|
child: child,
|
|
),
|
|
);
|
|
return DateTimeField.combine(date, time);
|
|
} else {
|
|
return currentValue;
|
|
}
|
|
},
|
|
onChanged: (input) => model.exerciseViewModel.setDatetimeExercise(input),
|
|
),
|
|
]),
|
|
)
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => {
|
|
if (_formKey.currentState.validate()) {
|
|
//model = ExerciseChangingViewModel(model.exerciseViewModel),
|
|
model.addExercise(),
|
|
Navigator.pop(context),
|
|
}
|
|
},
|
|
child: Icon(Icons.save,),
|
|
mini: true,
|
|
)
|
|
);
|
|
}
|
|
}
|