146 lines
3.6 KiB
Dart
146 lines
3.6 KiB
Dart
import 'package:fcs/domain/entities/carton.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/carton/model/carton_model.dart';
|
|
import 'package:fcs/pages/carton_search/carton_search.dart';
|
|
import 'package:fcs/pages/main/util.dart';
|
|
import 'package:fcs/pages/widgets/local_button.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:fcs/pages/widgets/local_title.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'carton_row.dart';
|
|
|
|
class MixCartonEditor extends StatefulWidget {
|
|
final Carton box;
|
|
MixCartonEditor({this.box});
|
|
|
|
@override
|
|
_MixCartonEditorState createState() => _MixCartonEditorState();
|
|
}
|
|
|
|
class _MixCartonEditorState extends State<MixCartonEditor> {
|
|
Carton _box;
|
|
bool _isLoading = false;
|
|
bool _isNew;
|
|
List<Carton> _cartons = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_box = widget.box;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final createBtn = LocalButton(
|
|
textKey: "box.mix_carton_btn",
|
|
callBack: _creatCarton,
|
|
);
|
|
|
|
final cargoTableTitleBox = LocalTitle(
|
|
textKey: "boxes.title",
|
|
trailing: IconButton(
|
|
icon: Icon(
|
|
Icons.add_circle,
|
|
color: primaryColor,
|
|
),
|
|
onPressed: () => searchCarton(context, callbackCartonSelect: (c) {
|
|
_addMixCarton(c);
|
|
}),
|
|
),
|
|
);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
leading: new IconButton(
|
|
icon: new Icon(
|
|
CupertinoIcons.back,
|
|
color: primaryColor,
|
|
),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
shadowColor: Colors.transparent,
|
|
backgroundColor: Colors.white,
|
|
title: LocalText(
|
|
context,
|
|
"box.min_caton.form.title",
|
|
fontSize: 20,
|
|
color: primaryColor,
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: ListView(
|
|
children: [
|
|
cargoTableTitleBox,
|
|
Column(
|
|
children: _getCartons(
|
|
context,
|
|
this._cartons,
|
|
)),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
createBtn
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
|
return cartons.map((c) {
|
|
return CartonRow(
|
|
key: ValueKey(c.id),
|
|
box: c,
|
|
onRemove: (carton) {
|
|
_removeMixCarton(carton);
|
|
},
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
_addMixCarton(Carton carton) {
|
|
if (carton == null) return;
|
|
if (this._cartons.any((c) => c.cartonNumber == carton.cartonNumber)) return;
|
|
setState(() {
|
|
this._cartons.add(carton);
|
|
});
|
|
}
|
|
|
|
_removeMixCarton(Carton carton) {
|
|
setState(() {
|
|
this._cartons.remove(carton);
|
|
});
|
|
}
|
|
|
|
_creatCarton() {
|
|
if ((this._cartons?.length ?? 0) == 0) {
|
|
showMsgDialog(context, "Error", "Expect at least one carton");
|
|
return;
|
|
}
|
|
Carton carton = Carton();
|
|
carton.id = _box.id;
|
|
carton.cartonType = _box.cartonType;
|
|
setState(() {
|
|
_isLoading = true;
|
|
});
|
|
try {
|
|
CartonModel cartonModel =
|
|
Provider.of<CartonModel>(context, listen: false);
|
|
} catch (e) {
|
|
showMsgDialog(context, "Error", e.toString());
|
|
} finally {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|