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.
252 lines
9.1 KiB
Dart
252 lines
9.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/controllers/localization/localization.dart';
|
|
import 'package:test_sa/models/lookup.dart';
|
|
import 'package:test_sa/models/subtitle.dart';
|
|
import 'package:test_sa/models/visits/visit.dart';
|
|
import 'package:test_sa/models/visits/visits_group.dart';
|
|
import 'package:test_sa/views/app_style/colors.dart';
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
import 'package:test_sa/views/widgets/app_text_form_field.dart';
|
|
import 'package:test_sa/views/widgets/buttons/app_button.dart';
|
|
import 'package:test_sa/views/widgets/buttons/app_small_button.dart';
|
|
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
|
|
import 'package:test_sa/views/widgets/images/one_image_picker.dart';
|
|
import 'package:test_sa/views/widgets/search/filter_item.dart';
|
|
import 'package:test_sa/views/widgets/visits/visit_status.dart';
|
|
class UpdateVisitsGroupSheet extends StatefulWidget {
|
|
final List<Visit> visits;
|
|
final String title;
|
|
const UpdateVisitsGroupSheet({Key key, this.visits, this.title}) : super(key: key);
|
|
|
|
@override
|
|
_UpdateVisitsGroupSheetState createState() => _UpdateVisitsGroupSheetState();
|
|
}
|
|
|
|
class _UpdateVisitsGroupSheetState extends State<UpdateVisitsGroupSheet> {
|
|
List<Lookup> status = [
|
|
Lookup(label: "Done", id: 0,),
|
|
Lookup(label: "Not Yet", id: 1),
|
|
Lookup(label: "On Hold", id: 2,),
|
|
];
|
|
|
|
List<Lookup> taskStatus = [
|
|
Lookup(label: "Passed", id: 0,),
|
|
Lookup(label: "Failed", id: 1),
|
|
];
|
|
VisitsGroup _group = VisitsGroup();
|
|
File _image;
|
|
Subtitle _subtitle;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_group.visits = widget.visits;
|
|
_group.date = DateTime.now();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_subtitle = AppLocalization.of(context).subtitle;
|
|
return Container(
|
|
height: MediaQuery.of(context).size.height / 1.3,
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 16.0 * AppStyle.getScaleFactor(context),
|
|
vertical: 8.0 * AppStyle.getScaleFactor(context),
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
widget.title ?? _subtitle.updateVisitsGroup,
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
ASmallButton(
|
|
text: _subtitle.cancel,
|
|
onPressed: (){
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
|
|
AOneImagePicker(
|
|
image: _image,
|
|
onPick: (image){
|
|
_image =image;
|
|
_group.image = base64Encode(image.readAsBytesSync());
|
|
},
|
|
),
|
|
SizedBox(height: 12 * AppStyle.getScaleFactor(context),),
|
|
ATextFormField(
|
|
initialValue: _group.jobSheetNumber,
|
|
hintText: _subtitle.jobSheetNumber,
|
|
style: Theme.of(context).textTheme.headline6,
|
|
onSaved: (value){
|
|
_group.jobSheetNumber = value;
|
|
},
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
ATextFormField(
|
|
initialValue: _group.workingHours,
|
|
hintText: _subtitle.workingHours,
|
|
style: Theme.of(context).textTheme.headline6,
|
|
onSaved: (value){
|
|
_group.workingHours = value;
|
|
},
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
ATextFormField(
|
|
initialValue: _group.travelingHours,
|
|
hintText: _subtitle.travelingHours,
|
|
style: Theme.of(context).textTheme.headline6,
|
|
onSaved: (value){
|
|
_group.travelingHours = value;
|
|
},
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
"${_subtitle.date} :",
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
ADatePicker(
|
|
date: _group.date ?? DateTime.now(),
|
|
onDatePicker: (date){
|
|
_group.date = date;
|
|
setState(() {});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
// SizedBox(height: 8 * AStyling.getScaleFactor(context),),
|
|
Text(
|
|
"${_subtitle.status} :",
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
Center(
|
|
child: Wrap(
|
|
spacing: 10,
|
|
runSpacing: 10,
|
|
children: List.generate(
|
|
status.length,
|
|
(index) {
|
|
bool isSelected = _group.status == status[index];
|
|
return FilterItem(
|
|
isSelected: isSelected,
|
|
onSelected: (){
|
|
if(isSelected)
|
|
_group.status = null;
|
|
else
|
|
_group.status = status[index];
|
|
|
|
setState(() {});
|
|
},
|
|
status: status[index],
|
|
);
|
|
}
|
|
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
"${_subtitle.taskStatus} :",
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
Center(
|
|
child: Wrap(
|
|
spacing: 10,
|
|
runSpacing: 10,
|
|
children: List.generate(
|
|
taskStatus.length,
|
|
(index) {
|
|
bool isSelected = _group.taskStatus == taskStatus[index];
|
|
return FilterItem(
|
|
isSelected: isSelected,
|
|
onSelected: (){
|
|
if(isSelected)
|
|
_group.taskStatus = null;
|
|
else
|
|
_group.taskStatus = taskStatus[index];
|
|
|
|
setState(() {});
|
|
},
|
|
status: taskStatus[index],
|
|
);
|
|
}
|
|
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 8 * AppStyle.getScaleFactor(context),),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: widget.visits.length,
|
|
itemBuilder: (context,index){
|
|
Visit visit = widget.visits[index];
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8),
|
|
margin: EdgeInsets.symmetric(vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: AColors.primaryColor,
|
|
borderRadius: BorderRadius.circular(
|
|
AppStyle.getBorderRadius(context)
|
|
),
|
|
boxShadow: [
|
|
AppStyle.boxShadow
|
|
]
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
"${_subtitle.sn}: "+visit.deviceSerialNumber ?? _subtitle.noSerialNumberFound,
|
|
style: Theme.of(context).textTheme.headline6.copyWith(
|
|
color: AColors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold
|
|
),
|
|
),
|
|
),
|
|
VisitStatusLabel(visit: visit,)
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
AButton(
|
|
text: _subtitle.update,
|
|
onPressed: (){
|
|
Navigator.of(context).pop(_group);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
Align(
|
|
alignment: Alignment.topRight,
|
|
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|