add FCS UI
This commit is contained in:
154
lib/pages/carton_size/carton_size_editor.dart
Normal file
154
lib/pages/carton_size/carton_size_editor.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/length_picker.dart';
|
||||
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'model/carton_size_model.dart';
|
||||
|
||||
class CartonSizeEditor extends StatefulWidget {
|
||||
final CartonSize cartonSize;
|
||||
CartonSizeEditor({this.cartonSize});
|
||||
|
||||
@override
|
||||
_CartonSizeEditorState createState() => _CartonSizeEditorState();
|
||||
}
|
||||
|
||||
class _CartonSizeEditorState extends State<CartonSizeEditor> {
|
||||
TextEditingController _nameController = new TextEditingController();
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
CartonSize _cartonSize;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.cartonSize != null) {
|
||||
_cartonSize = widget.cartonSize;
|
||||
_nameController.text = _cartonSize.name;
|
||||
_widthController.text = _cartonSize.width.toString();
|
||||
_heightController.text = _cartonSize.height.toString();
|
||||
_lengthController.text = _cartonSize.length.toString();
|
||||
} else {
|
||||
_lengthController.text = "12";
|
||||
_widthController.text = "12";
|
||||
_heightController.text = "12";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nameBox = InputText(
|
||||
labelTextKey: 'box.carton_size.name',
|
||||
iconData: Icons.text_format,
|
||||
controller: _nameController);
|
||||
|
||||
final lengthBox = LengthPicker(
|
||||
controller: _lengthController,
|
||||
lableKey: "box.length",
|
||||
);
|
||||
final widthBox = LengthPicker(
|
||||
controller: _widthController,
|
||||
lableKey: "box.width",
|
||||
);
|
||||
final heightBox = LengthPicker(
|
||||
controller: _heightController,
|
||||
lableKey: "box.height",
|
||||
);
|
||||
|
||||
final dimBox = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
|
||||
),
|
||||
SizedBox(child: lengthBox, width: 80),
|
||||
SizedBox(child: widthBox, width: 80),
|
||||
SizedBox(child: heightBox, width: 80),
|
||||
],
|
||||
);
|
||||
|
||||
final saveBtn = fcsButton(
|
||||
context,
|
||||
getLocalString(context, 'box.cargo.save.btn'),
|
||||
callack: () async {
|
||||
if (_nameController.text == "") {
|
||||
showMsgDialog(context, "Esrror", "Invalid carton size name!");
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
CartonSizeModel cartonSizeModel =
|
||||
Provider.of<CartonSizeModel>(context, listen: false);
|
||||
try {
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
CartonSize _cartonSize = CartonSize(
|
||||
name: _nameController.text, length: l, width: w, height: h);
|
||||
await cartonSizeModel.addCartonSize(_cartonSize);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon:
|
||||
new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
"box.carton_size",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
)),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: <Widget>[
|
||||
nameBox,
|
||||
dimBox,
|
||||
SizedBox(height: 40),
|
||||
saveBtn,
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
143
lib/pages/carton_size/carton_size_list.dart
Normal file
143
lib/pages/carton_size/carton_size_list.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.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_size_editor.dart';
|
||||
import 'model/carton_size_model.dart';
|
||||
|
||||
typedef void FindCallBack();
|
||||
|
||||
class CartonSizeList extends StatefulWidget {
|
||||
const CartonSizeList();
|
||||
@override
|
||||
_CartonSizeListState createState() => _CartonSizeListState();
|
||||
}
|
||||
|
||||
class _CartonSizeListState extends State<CartonSizeList> {
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
List<Widget> showCartonSize(
|
||||
BuildContext context, List<CartonSize> cartonSizes) {
|
||||
return cartonSizes.map((p) {
|
||||
return new ListTile(
|
||||
title: new Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
new Text(
|
||||
p.name,
|
||||
style: TextStyle(fontSize: 15.0),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: new Text(
|
||||
"(L${p.length}xW${p.width}xH${p.height})",
|
||||
style: new TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 15)
|
||||
],
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.remove, color: primaryColor),
|
||||
onPressed: () => _remove(p),
|
||||
)
|
||||
],
|
||||
));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<CartonSize> cartonSizes =
|
||||
Provider.of<CartonSizeModel>(context).cartonSizes;
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon:
|
||||
new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
"box.carton_size.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 18.0),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.add, color: primaryColor),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) => CartonSizeEditor()));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: showCartonSize(context, cartonSizes),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_remove(CartonSize cartonSize) {
|
||||
if (cartonSize == null) {
|
||||
showMsgDialog(context, "Esrror", "Invalid cartonsize!");
|
||||
return;
|
||||
}
|
||||
showConfirmDialog(context, "box.carton_size_remove.confirm",
|
||||
() => _removeCartonSize(cartonSize));
|
||||
}
|
||||
|
||||
_removeCartonSize(CartonSize cartonSize) async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
CartonSizeModel cartonSizeModel =
|
||||
Provider.of<CartonSizeModel>(context, listen: false);
|
||||
try {
|
||||
await cartonSizeModel.deleteCartonSize(cartonSize.id);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
36
lib/pages/carton_size/model/carton_size_model.dart
Normal file
36
lib/pages/carton_size/model/carton_size_model.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/entities/carton_size.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class CartonSizeModel extends BaseModel {
|
||||
List<CartonSize> cartonSizes = [];
|
||||
final log = Logger('CartonSizeModel');
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
cartonSizes = [
|
||||
CartonSize(
|
||||
id: "1", name: "FCS Small Box", length: 16, width: 12, height: 12),
|
||||
CartonSize(
|
||||
id: "2", name: "FCS Medium Box", length: 22, width: 16, height: 15),
|
||||
CartonSize(
|
||||
id: "3", name: "FCS Large Box", length: 28, width: 15, height: 16)
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
|
||||
cartonSizes = [];
|
||||
}
|
||||
|
||||
Future<void> addCartonSize(CartonSize cartonSize) async {}
|
||||
|
||||
Future<void> deleteCartonSize(String id) async {}
|
||||
}
|
||||
Reference in New Issue
Block a user