Files
fcs/lib/fcs/common/pages/home_page.dart

344 lines
13 KiB
Dart
Raw Normal View History

2020-09-13 21:49:39 +06:30
import 'package:fcs/fcs/common/domain/entities/user.dart';
2020-09-04 15:30:10 +06:30
import 'package:fcs/fcs/common/localization/transalation.dart';
2020-09-11 16:14:36 +06:30
import 'package:fcs/fcs/common/pages/customers/customer_list.dart';
2020-09-13 21:49:39 +06:30
import 'package:fcs/fcs/common/pages/faq/faq_list_page.dart';
2020-09-04 15:30:10 +06:30
import 'package:fcs/fcs/common/pages/model/language_model.dart';
2020-09-04 01:42:58 +06:30
import 'package:fcs/fcs/common/pages/model/main_model.dart';
2020-09-13 21:49:39 +06:30
import 'package:fcs/fcs/common/pages/staff/staff_list.dart';
import 'package:fcs/fcs/common/pages/util.dart';
2020-09-04 15:30:10 +06:30
import 'package:fcs/fcs/common/pages/widgets/action_button.dart';
import 'package:fcs/fcs/common/pages/widgets/bottom_widgets.dart';
2020-06-26 16:04:40 +06:30
import 'package:fcs/pages/discount_list.dart';
2020-08-30 21:26:37 +06:30
import 'package:fcs/pages/notification_list.dart';
2020-06-26 16:04:40 +06:30
import 'package:fcs/pages/payment_method_page.dart';
2020-06-01 14:24:45 +06:30
import 'package:fcs/pages/shipment_list.dart';
2020-08-30 21:26:37 +06:30
import 'package:fcs/pages/term.dart';
2020-06-04 01:36:49 +06:30
import 'package:fcs/pages_fcs/box_list.dart';
2020-06-26 16:17:40 +06:30
import 'package:fcs/pages_fcs/delivery_list.dart';
2020-06-01 11:52:12 +06:30
import 'package:fcs/pages_fcs/package_list.dart';
2020-05-29 07:45:27 +06:30
import 'package:fcs/widget/banner.dart';
2020-08-30 21:26:37 +06:30
import 'package:fcs/widget/bottom_up_page_route.dart';
2020-05-29 07:45:27 +06:30
import 'package:fcs/widget/offline_redirect.dart';
2020-09-10 02:13:22 +06:30
import 'package:fcs/widget/right_left_page_rout.dart';
2020-05-29 15:53:37 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
2020-08-30 21:26:37 +06:30
import 'package:flutter_icons/flutter_icons.dart';
2020-05-29 15:53:37 +06:30
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
2020-05-29 07:45:27 +06:30
2020-08-30 21:26:37 +06:30
import '../../../pages/buying_online.dart';
import '../../../pages/fcs_profile_page.dart';
import '../../../pages/invoice/invoce_list.dart';
import '../../../pages/pickup_list.dart';
import '../../../pages/shipment_rates.dart';
2020-09-04 15:30:10 +06:30
import '../helpers/theme.dart';
2020-09-13 21:49:39 +06:30
import 'profile/profile_page.dart';
2020-08-30 21:26:37 +06:30
import 'signin/signin_page.dart';
2020-05-29 07:45:27 +06:30
final msgLog = Logger('backgroundMessageHandler');
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final log = Logger('_HomePageState');
2020-05-31 15:00:11 +06:30
bool login = false;
bool customer = true;
2020-09-04 15:30:10 +06:30
List<bool> isSelected = [true, false];
2020-05-29 07:45:27 +06:30
@override
void initState() {
super.initState();
}
void dispose() {
super.dispose();
}
static final List<String> chartDropdownItems = [
'Last 7 days',
'Last month',
'Last three months'
];
String actualDropdown = chartDropdownItems[0];
int actualChart = 0;
final numberFormatter = new NumberFormat("#,###");
String pin;
@override
Widget build(BuildContext context) {
2020-09-13 21:49:39 +06:30
User user = Provider.of<MainModel>(context).user;
2020-06-01 14:24:45 +06:30
login = Provider.of<MainModel>(context).isLogin();
2020-09-11 16:14:36 +06:30
// var owner =true;// Provider.of<MainModel>(context).isOwner();
2020-06-03 00:42:31 +06:30
var customer = Provider.of<MainModel>(context).isCustomer();
2020-09-04 15:30:10 +06:30
LanguageModel languageModel = Provider.of<LanguageModel>(context);
2020-06-03 00:42:31 +06:30
2020-09-07 16:05:28 +06:30
final faqBtn = _buildBtn("faq.btn",
icon: MaterialCommunityIcons.frequently_asked_questions,
btnCallback: () => Navigator.of(context).push(CupertinoPageRoute(
2020-09-13 21:49:39 +06:30
builder: (context) => FAQListPage(),
2020-09-07 16:05:28 +06:30
)));
2020-09-04 15:30:10 +06:30
final packagesBtn = _buildBtn("package.name",
2020-06-01 11:52:12 +06:30
icon: Octicons.package,
2020-06-02 00:00:05 +06:30
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(PackageList())));
2020-05-29 07:45:27 +06:30
2020-09-04 15:30:10 +06:30
final boxesBtn = _buildBtn("boxes.name",
2020-06-04 01:36:49 +06:30
icon: MaterialCommunityIcons.package,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(BoxList())));
2020-09-04 15:30:10 +06:30
final pickUpBtn = _buildBtn("pickup",
2020-06-03 00:42:31 +06:30
icon: SimpleLineIcons.direction,
2020-06-01 14:24:45 +06:30
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(PickUpList())));
2020-05-29 15:54:26 +06:30
2020-09-04 15:30:10 +06:30
final shipmentCostBtn = _buildBtn("rate",
2020-05-31 15:00:11 +06:30
icon: FontAwesomeIcons.calculator,
2020-06-01 14:24:45 +06:30
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(ShipmentRates())));
2020-05-29 15:54:26 +06:30
2020-09-04 15:30:10 +06:30
final fcsProfileBtn = _buildBtn("fcs.btn",
2020-06-02 00:00:05 +06:30
// imgIcon: Image.asset("assets/logo_btn.png", height: 25,color:Colors.white),
icon: MaterialCommunityIcons.home_city,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(FCSProfilePage())));
2020-05-29 15:54:26 +06:30
2020-09-04 15:30:10 +06:30
final shipmentBtn = _buildBtn("shipment.title",
2020-05-31 15:00:11 +06:30
icon: Ionicons.ios_airplane,
2020-05-29 07:45:27 +06:30
imgIcon: Image.asset(
"assets/truck.png",
width: 50,
height: 50,
color: primaryColor,
),
2020-06-02 00:00:05 +06:30
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(ShipmentList())));
2020-05-29 07:45:27 +06:30
2020-09-04 15:30:10 +06:30
final buyingBtn = _buildBtn("buy_online",
2020-05-31 15:00:11 +06:30
icon: MaterialCommunityIcons.cart_outline, btnCallback: () {
2020-06-01 14:24:45 +06:30
Navigator.push(context, BottomUpPageRoute(BuyingOnlinePage())
// MaterialPageRoute(builder: (context) => BuyingOnlinePage()),
);
2020-05-29 16:14:17 +06:30
});
2020-06-02 00:00:05 +06:30
final notiBtn =
2020-09-04 15:30:10 +06:30
_buildBtn("message.btn", icon: Icons.message, btnCallback: () {
2020-05-29 07:45:27 +06:30
Navigator.push(
context,
2020-05-31 15:00:11 +06:30
BottomUpPageRoute(NotificationList()),
2020-05-29 07:45:27 +06:30
);
});
2020-09-04 15:30:10 +06:30
final staffBtn = _buildBtn("staff.title",
2020-06-02 00:00:05 +06:30
icon: MaterialCommunityIcons.worker,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(StaffList())));
2020-05-29 16:14:17 +06:30
2020-09-04 15:30:10 +06:30
final customersBtn = _buildBtn("customers.btn",
2020-06-02 00:00:05 +06:30
icon: Feather.users,
btnCallback: () =>
2020-06-02 14:52:31 +06:30
Navigator.of(context).push(BottomUpPageRoute(CustomerList())));
2020-06-02 00:00:05 +06:30
2020-09-04 15:30:10 +06:30
final invoicesBtn = _buildBtn("invoices.btn",
2020-06-02 00:00:05 +06:30
icon: FontAwesomeIcons.fileInvoice,
btnCallback: () =>
2020-06-02 14:56:51 +06:30
Navigator.of(context).push(BottomUpPageRoute(InvoiceList())));
2020-05-29 07:45:27 +06:30
2020-09-04 15:30:10 +06:30
final paymentMethodBtn = _buildBtn("payment.method.btn",
2020-06-26 16:04:40 +06:30
icon: FontAwesomeIcons.creditCard,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(PaymentMethodPage())));
2020-09-04 15:30:10 +06:30
final discountBtn = _buildBtn("discount.btn",
icon: Entypo.price_ribbon,
2020-06-26 16:04:40 +06:30
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(DiscountList())));
2020-09-04 15:30:10 +06:30
final termBtn = _buildBtn("term.btn",
2020-06-02 14:52:31 +06:30
icon: FontAwesomeIcons.info,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(Term())));
2020-09-04 15:30:10 +06:30
final deliveryBtn = _buildBtn("delivery.title",
2020-06-26 16:17:40 +06:30
icon: MaterialCommunityIcons.truck_fast,
btnCallback: () =>
Navigator.of(context).push(BottomUpPageRoute(DeliverList())));
2020-06-02 14:52:31 +06:30
2020-05-31 15:00:11 +06:30
List<Widget> widgets = [];
2020-09-07 16:05:28 +06:30
widgets.add(faqBtn);
2020-09-13 21:49:39 +06:30
if (user != null) {
// customer ? widgets.add(buyingBtn) : "";
// customer || owner ? widgets.add(pickUpBtn) : "";
// !customer ? widgets.add(shipmentBtn) : "";
// customer || owner ? widgets.add(notiBtn) : "";
user.hasStaffs() ? widgets.add(staffBtn) : "";
// owner ? widgets.add(fcsProfileBtn) : "";
// widgets.add(shipmentCostBtn);
// customer || owner ? widgets.add(packagesBtn) : "";
// owner ? widgets.add(boxesBtn) : "";
// owner ? widgets.add(deliveryBtn) : "";
user.hasCustomers() ? widgets.add(customersBtn) : "";
// customer || owner ? widgets.add(invoicesBtn) : "";
// owner ? widgets.add(paymentMethodBtn) : "";
// owner ? widgets.add(discountBtn) : "";
// widgets.add(termBtn);
}
2020-05-29 07:45:27 +06:30
return OfflineRedirect(
child: FlavorBanner(
child: Scaffold(
appBar: AppBar(
2020-05-29 15:53:37 +06:30
elevation: 0,
2020-05-29 07:45:27 +06:30
backgroundColor: primaryColor,
title: ClipRRect(
2020-05-29 15:53:37 +06:30
child: Image.asset("assets/logo.jpg", height: 40),
2020-05-31 16:14:56 +06:30
borderRadius: new BorderRadius.circular(30.0),
2020-05-29 07:45:27 +06:30
),
2020-05-31 15:00:11 +06:30
actions: login
? <Widget>[
2020-06-02 00:00:05 +06:30
ToggleButtons(
children: <Widget>[
Image.asset(
2020-06-24 16:06:40 +06:30
'icons/flags/png/us.png',
2020-06-02 00:00:05 +06:30
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,
2020-09-04 15:30:10 +06:30
isSelected: languageModel.currentState,
2020-09-12 03:34:52 +06:30
selectedBorderColor: Colors.white24,
2020-05-31 15:00:11 +06:30
),
IconButton(
onPressed: () {
2020-08-26 16:01:13 +06:30
Navigator.of(context)
.push(RightLeftPageRoute(Profile()));
2020-05-31 15:00:11 +06:30
},
iconSize: 30,
2020-06-24 16:06:40 +06:30
icon: Icon(Icons.account_circle),
2020-05-31 15:00:11 +06:30
),
]
2020-05-31 16:14:56 +06:30
: <Widget>[
2020-06-02 00:00:05 +06:30
ToggleButtons(
children: <Widget>[
Image.asset(
2020-06-24 16:06:40 +06:30
'icons/flags/png/us.png',
2020-06-02 00:00:05 +06:30
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,
2020-09-04 15:30:10 +06:30
isSelected: languageModel.currentState,
2020-06-02 00:00:05 +06:30
),
2020-06-01 14:24:45 +06:30
FlatButton(
2020-05-31 15:00:11 +06:30
onPressed: () {
2020-06-02 14:56:51 +06:30
Navigator.of(context)
.push(BottomUpPageRoute(SigninPage()));
2020-05-31 15:00:11 +06:30
},
// iconSize: 30,
2020-06-01 14:24:45 +06:30
child: Text(
2020-06-02 00:00:05 +06:30
"Sign In",
2020-06-01 14:24:45 +06:30
style: siginButtonStyle,
),
2020-06-02 14:52:31 +06:30
),
2020-05-31 15:00:11 +06:30
]),
2020-05-29 15:53:37 +06:30
body: Container(
decoration: BoxDecoration(
gradient:
// RadialGradient(
// center: const Alignment(-0.7, 0.6), // near the top right
// radius: 0.6,
// colors: [
// secondaryColor,
// primaryColor, // yellow sun
// ],
// stops: [0.4, 1.0],
// )
2020-05-31 15:00:11 +06:30
LinearGradient(
begin: Alignment.topCenter,
end: Alignment
.bottomCenter, // 10% of the width, so there are ten blinds.
colors: [
Color(0xd0272262),
Color(0xfa272262),
// Color(0xa0ff4400),
// secondaryColor,
], // whitish to gray
),
2020-05-29 21:42:00 +06:30
// SweepGradient(
// center: FractionalOffset.centerLeft,
// startAngle: 0.0,
// endAngle: math.pi * 2,
// colors: const <Color>[
// secondaryColor,
// primaryColor,
// secondaryColor,
// primaryColor,
// secondaryColor,
// ],
// stops: const <double>[0.0, 0.25, 0.5, 0.75, 1.0],
// ),
2020-05-29 07:45:27 +06:30
),
2020-05-31 15:00:11 +06:30
child: Column(
children: <Widget>[
2020-09-13 21:49:39 +06:30
user.requested
? Container(
padding: const EdgeInsets.all(8.0),
child: Text(
getLocalString(
context, "home.invitation.request.msg"),
style: TextStyle(color: Colors.white70),
),
)
: Container(),
2020-05-31 15:00:11 +06:30
Expanded(
2020-09-04 15:30:10 +06:30
child: ListView(children: [
Wrap(
alignment: WrapAlignment.center,
children: widgets,
),
]),
2020-05-31 15:00:11 +06:30
),
2020-09-07 16:05:28 +06:30
BottomWidgets(),
2020-05-31 15:00:11 +06:30
],
2020-06-01 11:52:12 +06:30
))),
2020-05-29 07:45:27 +06:30
),
);
}
2020-06-02 00:00:05 +06:30
_langChange(index) {
2020-09-07 16:05:28 +06:30
var languageModel = Provider.of<LanguageModel>(context, listen: false);
2020-06-02 14:56:51 +06:30
languageModel.saveLanguage(Translation().supportedLanguages[index]);
2020-06-02 00:00:05 +06:30
setState(() {
isSelected.asMap().forEach((i, e) {
isSelected[i] = false;
});
isSelected[index] = !isSelected[index];
});
}
2020-05-29 07:45:27 +06:30
Widget _buildBtn(String title,
{Image imgIcon, IconData icon, BtnCallback btnCallback}) {
2020-09-07 16:05:28 +06:30
return ActionButton(
title: title, imgIcon: imgIcon, icon: icon, btnCallback: btnCallback);
2020-05-31 15:00:11 +06:30
}
2020-05-29 07:45:27 +06:30
}