add packages, receiving & processing
This commit is contained in:
@@ -2,7 +2,9 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/user.dart';
|
||||
import 'package:fcs/helpers/shared_pref.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/transalation.dart';
|
||||
import 'package:fcs/pages/box/box_list.dart';
|
||||
@@ -17,23 +19,27 @@ import 'package:fcs/pages/fcs_shipment/fcs_shipment_list.dart';
|
||||
import 'package:fcs/pages/invoice/invoce_list.dart';
|
||||
import 'package:fcs/pages/main/model/language_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/package/package_info.dart';
|
||||
import 'package:fcs/pages/package/package_list.dart';
|
||||
import 'package:fcs/pages/processing/processing_list.dart';
|
||||
import 'package:fcs/pages/rates/shipment_rates.dart';
|
||||
import 'package:fcs/pages/receiving/receiving_list.dart';
|
||||
import 'package:fcs/pages/shipment/shipment_list.dart';
|
||||
import 'package:fcs/pages/staff/staff_list.dart';
|
||||
import 'package:fcs/pages/widgets/task_button.dart';
|
||||
import 'package:fcs/pages/widgets/badge.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_widgets.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:fcs/pages/widgets/right_left_page_rout.dart';
|
||||
import 'package:fcs/pages/widgets/task_button.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -52,10 +58,12 @@ class HomePage extends StatefulWidget {
|
||||
class _HomePageState extends State<HomePage> {
|
||||
final log = Logger('_HomePageState');
|
||||
bool login = false;
|
||||
bool customer = true;
|
||||
bool _isLoading = false;
|
||||
List<bool> isSelected = [true, false];
|
||||
static FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
TextEditingController _searchCtl = TextEditingController();
|
||||
List<bool> isFcs = [false];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -73,6 +81,18 @@ class _HomePageState extends State<HomePage> {
|
||||
mainModel.setMessaginToken = token;
|
||||
});
|
||||
_initLocalNotifications();
|
||||
_loadStaffMode(mainModel.isCustomer());
|
||||
}
|
||||
|
||||
_loadStaffMode(bool isCustomer) async {
|
||||
bool staffMode = await SharedPref.getStaffMode();
|
||||
setState(() {
|
||||
if (isCustomer) {
|
||||
isFcs[0] = false;
|
||||
} else {
|
||||
isFcs[0] = staffMode;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String notiUserID, notiUserName;
|
||||
@@ -189,7 +209,6 @@ class _HomePageState extends State<HomePage> {
|
||||
if (user == null) {
|
||||
return Container();
|
||||
}
|
||||
customer = Provider.of<MainModel>(context).isCustomer();
|
||||
|
||||
login = Provider.of<MainModel>(context).isLogin();
|
||||
LanguageModel languageModel = Provider.of<LanguageModel>(context);
|
||||
@@ -204,6 +223,12 @@ class _HomePageState extends State<HomePage> {
|
||||
icon: Octicons.package,
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => PackageList())));
|
||||
final packagesBtnFcs = TaskButton("package.btn.name",
|
||||
icon: Octicons.package,
|
||||
btnCallback: () => Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) => PackageList(
|
||||
onlyFcs: true,
|
||||
))));
|
||||
|
||||
final receivingBtn = TaskButton("receiving.title",
|
||||
icon: MaterialCommunityIcons.inbox_arrow_down,
|
||||
@@ -214,15 +239,20 @@ class _HomePageState extends State<HomePage> {
|
||||
icon: FontAwesome.dropbox,
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => ProcessingList())));
|
||||
final boxesBtn = TaskButton("boxes.name",
|
||||
final cartonBtn = TaskButton("boxes.name",
|
||||
icon: MaterialCommunityIcons.package,
|
||||
btnCallback: () =>
|
||||
Navigator.of(context).push(BottomUpPageRoute(BoxList())));
|
||||
btnCallback: () => Navigator.of(context)
|
||||
.push<void>(CupertinoPageRoute(builder: (context) => BoxList())));
|
||||
|
||||
final pickUpBtn = TaskButton("shipment",
|
||||
final shipmentBtn = TaskButton("shipment",
|
||||
icon: SimpleLineIcons.direction,
|
||||
btnCallback: () =>
|
||||
Navigator.of(context).push(BottomUpPageRoute(ShipmentList())));
|
||||
btnCallback: () => Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: (context) => ShipmentList())));
|
||||
|
||||
final shipmentBtnFcs = TaskButton("shipment",
|
||||
icon: SimpleLineIcons.direction,
|
||||
btnCallback: () => Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: (context) => ShipmentList())));
|
||||
|
||||
final shipmentCostBtn = TaskButton("rate",
|
||||
icon: FontAwesomeIcons.calculator,
|
||||
@@ -231,21 +261,19 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
final fcsShipmentBtn = TaskButton("FCSshipment.title",
|
||||
icon: Ionicons.ios_airplane,
|
||||
btnCallback: () => Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
btnCallback: () => Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => FcsShipmentList(),
|
||||
)));
|
||||
|
||||
final notiBtnOrg =
|
||||
TaskButton("message.btn", icon: Icons.message, btnCallback: () {
|
||||
MessageModel messageModel =
|
||||
Provider.of<MessageModel>(context, listen: false);
|
||||
messageModel.initQuery(user.id);
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(MessageDetail(
|
||||
messageModel: messageModel,
|
||||
)),
|
||||
).then((value) {
|
||||
Navigator.of(context)
|
||||
.push(CupertinoPageRoute(
|
||||
builder: (context) => MessageDetail(messageModel: messageModel),
|
||||
))
|
||||
.then((value) {
|
||||
if (user.userUnseenCount > 0) {
|
||||
messageModel.seenMessages(user.id, true);
|
||||
}
|
||||
@@ -272,128 +300,204 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
final invoicesBtn = TaskButton("invoices.btn",
|
||||
icon: FontAwesomeIcons.fileInvoice,
|
||||
btnCallback: () =>
|
||||
Navigator.of(context).push(BottomUpPageRoute(InvoiceList())));
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => InvoiceList())));
|
||||
final invoicesBtnFcs = TaskButton("invoices.btn",
|
||||
icon: FontAwesomeIcons.fileInvoice,
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => InvoiceList())));
|
||||
|
||||
final discountBtn = TaskButton("discount.btn",
|
||||
icon: Entypo.price_ribbon,
|
||||
btnCallback: () =>
|
||||
Navigator.of(context).push(BottomUpPageRoute(DiscountList())));
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => DiscountList())));
|
||||
|
||||
final deliveryBtn = TaskButton("delivery.title",
|
||||
icon: MaterialCommunityIcons.truck_fast,
|
||||
btnCallback: () =>
|
||||
Navigator.of(context).push(BottomUpPageRoute(DeliverList())));
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => DeliverList())));
|
||||
|
||||
List<Widget> widgets = [];
|
||||
if (user != null) {
|
||||
true ? widgets.add(pickUpBtn) : "";
|
||||
!customer ? widgets.add(fcsShipmentBtn) : "";
|
||||
customer ? widgets.add(notiBtn) : "";
|
||||
user.hasStaffs() ? widgets.add(staffBtn) : "";
|
||||
widgets.add(shipmentCostBtn);
|
||||
user.hasPackages() ? widgets.add(packagesBtn) : "";
|
||||
user.hasPackages() ? widgets.add(receivingBtn) : "";
|
||||
user.hasPackages() ? widgets.add(processingBtn) : "";
|
||||
true ? widgets.add(boxesBtn) : "";
|
||||
true ? widgets.add(deliveryBtn) : "";
|
||||
user.hasCustomers() ? widgets.add(customersBtn) : "";
|
||||
true ? widgets.add(invoicesBtn) : "";
|
||||
// true ? widgets.add(discountBtn) : "";
|
||||
}
|
||||
widgets.add(notiBtn);
|
||||
widgets.add(packagesBtn);
|
||||
widgets.add(shipmentBtn);
|
||||
widgets.add(invoicesBtn);
|
||||
widgets.add(faqBtn);
|
||||
return OfflineRedirect(
|
||||
child: FlavorBanner(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor: primaryColor,
|
||||
title: ClipRRect(
|
||||
child: Image.asset("assets/logo.jpg", height: 40),
|
||||
borderRadius: new BorderRadius.circular(30.0),
|
||||
),
|
||||
actions: login
|
||||
? <Widget>[
|
||||
ToggleButtons(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'icons/flags/png/us.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
),
|
||||
Image.asset(
|
||||
'icons/flags/png/mm.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
)
|
||||
],
|
||||
onPressed: _langChange,
|
||||
isSelected: languageModel.currentState,
|
||||
selectedBorderColor: Colors.white24,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(RightLeftPageRoute(Profile()));
|
||||
},
|
||||
iconSize: 30,
|
||||
icon: Icon(Icons.account_circle),
|
||||
),
|
||||
]
|
||||
: <Widget>[
|
||||
ToggleButtons(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'icons/flags/png/us.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
),
|
||||
Image.asset(
|
||||
'icons/flags/png/mm.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
)
|
||||
],
|
||||
onPressed: _langChange,
|
||||
isSelected: languageModel.currentState,
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(BottomUpPageRoute(SigninPage()));
|
||||
},
|
||||
child: Text(
|
||||
"Sign In",
|
||||
style: siginButtonStyle,
|
||||
),
|
||||
widgets.add(shipmentCostBtn);
|
||||
|
||||
List<Widget> widgetsFcs = [];
|
||||
if (user.hasPackages()) widgetsFcs.add(packagesBtnFcs);
|
||||
if (user.hasShipment()) widgetsFcs.add(shipmentBtnFcs);
|
||||
if (user.hasInvoices()) widgetsFcs.add(invoicesBtnFcs);
|
||||
|
||||
if (user.hasFcsShipments()) widgetsFcs.add(fcsShipmentBtn);
|
||||
if (user.hasReceiving()) widgetsFcs.add(receivingBtn);
|
||||
if (user.hasProcessing()) widgetsFcs.add(processingBtn);
|
||||
if (user.hasCarton()) widgetsFcs.add(cartonBtn);
|
||||
if (user.hasDeliveries()) widgetsFcs.add(deliveryBtn);
|
||||
if (user.hasCustomers()) widgetsFcs.add(customersBtn);
|
||||
if (user.hasAdmin()) widgetsFcs.add(discountBtn);
|
||||
if (user.hasStaffs()) widgetsFcs.add(staffBtn);
|
||||
|
||||
final fcsToggle = ToggleButtons(
|
||||
selectedColor: Colors.white,
|
||||
children: <Widget>[
|
||||
Icon(MaterialCommunityIcons.worker),
|
||||
],
|
||||
onPressed: (i) => this.setState(() {
|
||||
isFcs[0] = !isFcs[0];
|
||||
SharedPref.saveStaffMode(isFcs[0]);
|
||||
}),
|
||||
isSelected: isFcs,
|
||||
selectedBorderColor: Colors.white24,
|
||||
);
|
||||
final langToggle = ToggleButtons(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'icons/flags/png/us.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
),
|
||||
Image.asset(
|
||||
'icons/flags/png/mm.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
)
|
||||
],
|
||||
onPressed: _langChange,
|
||||
isSelected: languageModel.currentState,
|
||||
selectedBorderColor: Colors.white24,
|
||||
);
|
||||
final signinBtn = FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(BottomUpPageRoute(SigninPage()));
|
||||
},
|
||||
child: Text(
|
||||
"Sign In",
|
||||
style: siginButtonStyle,
|
||||
),
|
||||
);
|
||||
final profileBtn = IconButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(RightLeftPageRoute(Profile()));
|
||||
},
|
||||
iconSize: 30,
|
||||
icon: Icon(Icons.account_circle),
|
||||
);
|
||||
|
||||
var searchInput = Row(children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 3, left: 5, right: 5, top: 3),
|
||||
child: Theme(
|
||||
data: new ThemeData(
|
||||
primaryColor: primaryColor,
|
||||
primaryColorDark: primaryColor,
|
||||
),
|
||||
child: TextField(
|
||||
style: TextStyle(color: Colors.white),
|
||||
controller: _searchCtl,
|
||||
scrollPadding: EdgeInsets.all(0),
|
||||
decoration: new InputDecoration(
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||
borderSide:
|
||||
const BorderSide(color: Colors.white, width: 1.5),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||
borderSide:
|
||||
const BorderSide(color: Colors.white, width: 1.5),
|
||||
),
|
||||
contentPadding: EdgeInsets.only(top: 1, bottom: 1),
|
||||
isDense: true,
|
||||
hintText: getLocalString(context, "home.search"),
|
||||
hintStyle: languageModel.isEng
|
||||
? newLabelStyle(color: Colors.white60)
|
||||
: newLabelStyleMM(color: Colors.white60),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search,
|
||||
color: Colors.grey,
|
||||
),
|
||||
suffixIcon: InkWell(
|
||||
onTap: () => {_searchCtl.clear()},
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
suffixStyle: const TextStyle(color: primaryColor)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: LocalText(
|
||||
context,
|
||||
"home.search.btn",
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
onTap: _lookup,
|
||||
)
|
||||
]);
|
||||
widgets.insert(0, searchInput);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: OfflineRedirect(
|
||||
child: FlavorBanner(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor: primaryColor,
|
||||
title: ClipRRect(
|
||||
child: Image.asset("assets/logo.jpg", height: 40),
|
||||
borderRadius: new BorderRadius.circular(30.0),
|
||||
),
|
||||
actions: login
|
||||
? user.isCustomer()
|
||||
? <Widget>[
|
||||
langToggle,
|
||||
profileBtn,
|
||||
]
|
||||
: <Widget>[
|
||||
fcsToggle,
|
||||
langToggle,
|
||||
profileBtn,
|
||||
]
|
||||
: <Widget>[
|
||||
langToggle,
|
||||
signinBtn,
|
||||
]),
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xd0272262),
|
||||
Color(0xfa272262),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Column(children: [
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: isFcs[0] ? widgetsFcs : widgets,
|
||||
),
|
||||
]),
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xd0272262),
|
||||
Color(0xfa272262),
|
||||
SizedBox(height: 50),
|
||||
BottomWidgets(),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Column(children: [
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: widgets,
|
||||
),
|
||||
]),
|
||||
BottomWidgets(),
|
||||
],
|
||||
))),
|
||||
))),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -408,4 +512,34 @@ class _HomePageState extends State<HomePage> {
|
||||
isSelected[index] = !isSelected[index];
|
||||
});
|
||||
}
|
||||
|
||||
_lookup() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
String term = _searchCtl.text;
|
||||
if (term == null || term.trim() == "") return;
|
||||
var packageModel = Provider.of<PackageModel>(context, listen: false);
|
||||
Package package = await packageModel.lookupPackage(term);
|
||||
if (package == null) {
|
||||
showMsgDialog(context, "Not found", "Tracking ID - '$term' not found!");
|
||||
return;
|
||||
}
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(PackageInfo(
|
||||
package: package,
|
||||
isSearchResult: true,
|
||||
)),
|
||||
);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user