318 lines
10 KiB
Dart
318 lines
10 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||
|
|
import 'package:logging/logging.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import 'package:url_launcher/url_launcher.dart';
|
||
|
|
import 'package:fcs/model/announcement_model.dart';
|
||
|
|
import 'package:fcs/model/buyer_model.dart';
|
||
|
|
import 'package:fcs/model/do_model.dart';
|
||
|
|
import 'package:fcs/model/language_model.dart';
|
||
|
|
import 'package:fcs/model/notification_model.dart';
|
||
|
|
import 'package:fcs/model/po_model.dart';
|
||
|
|
import 'package:fcs/model/user_model.dart';
|
||
|
|
import 'package:fcs/theme/theme.dart';
|
||
|
|
import 'package:fcs/vo/buyer.dart';
|
||
|
|
import 'package:fcs/widget/local_text.dart';
|
||
|
|
import 'package:fcs/widget/localization/app_translations.dart';
|
||
|
|
import 'package:fcs/vo/notification.dart' as Noti;
|
||
|
|
|
||
|
|
import 'announcement.dart';
|
||
|
|
import 'buyer_info.dart';
|
||
|
|
import 'do/do_approve.dart';
|
||
|
|
import 'log_list.dart';
|
||
|
|
import 'my_registeration_info.dart';
|
||
|
|
import 'po/po_submission_form.dart';
|
||
|
|
import 'products_list.dart';
|
||
|
|
import 'user_editor.dart';
|
||
|
|
|
||
|
|
final log = Logger('Util');
|
||
|
|
|
||
|
|
void showMsgDialog(BuildContext context, String title, String msg) {
|
||
|
|
showDialog(
|
||
|
|
context: context,
|
||
|
|
builder: (_) {
|
||
|
|
return AlertDialog(
|
||
|
|
title: new Text(title),
|
||
|
|
content: new Text(msg),
|
||
|
|
actions: <Widget>[
|
||
|
|
new FlatButton(
|
||
|
|
child: new Text("Close"),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
},
|
||
|
|
),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
var selectedColor;
|
||
|
|
void showColorPicker(BuildContext context, Color color, callback(Color color)) {
|
||
|
|
showDialog(
|
||
|
|
context: context,
|
||
|
|
child: AlertDialog(
|
||
|
|
shape: RoundedRectangleBorder(
|
||
|
|
borderRadius: BorderRadius.all(Radius.circular(32.0))),
|
||
|
|
title: const Text('Pick product color'),
|
||
|
|
content: SingleChildScrollView(
|
||
|
|
child: ColorPicker(
|
||
|
|
pickerColor: color.value == 0 ? Colors.red : color,
|
||
|
|
pickerAreaHeightPercent: 0.6,
|
||
|
|
onColorChanged: (Color value) {
|
||
|
|
selectedColor = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
),
|
||
|
|
actions: <Widget>[
|
||
|
|
FlatButton(
|
||
|
|
child: const Text('Choose'),
|
||
|
|
onPressed: () {
|
||
|
|
callback(selectedColor == null ? Colors.red : selectedColor);
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
},
|
||
|
|
),
|
||
|
|
FlatButton(
|
||
|
|
child: const Text('Cancel'),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
},
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> showConfirmDialog(
|
||
|
|
BuildContext context, String translationKey, ok(),
|
||
|
|
{List<String> translationVariables}) async {
|
||
|
|
await showDialog(
|
||
|
|
context: context,
|
||
|
|
builder: (_) {
|
||
|
|
return AlertDialog(
|
||
|
|
title: Center(
|
||
|
|
child: LocalText(
|
||
|
|
context,
|
||
|
|
translationKey,
|
||
|
|
translationVariables: translationVariables,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
content: Container(
|
||
|
|
child: Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
|
children: <Widget>[
|
||
|
|
FlatButton(
|
||
|
|
child: Text(
|
||
|
|
AppTranslations.of(context).text('Cancel'),
|
||
|
|
style: Provider.of<LanguageModel>(context).isEng
|
||
|
|
? TextStyle()
|
||
|
|
: TextStyle(fontFamily: 'MyanmarUnicode'),
|
||
|
|
),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
}),
|
||
|
|
FlatButton(
|
||
|
|
color: primaryColor,
|
||
|
|
child: Text(AppTranslations.of(context).text('Ok'),
|
||
|
|
style: Provider.of<LanguageModel>(context).isEng
|
||
|
|
? TextStyle(
|
||
|
|
color: Colors.white,
|
||
|
|
fontWeight: FontWeight.bold)
|
||
|
|
: TextStyle(
|
||
|
|
color: Colors.white,
|
||
|
|
fontWeight: FontWeight.bold,
|
||
|
|
fontFamily: 'MyanmarUnicode')),
|
||
|
|
onPressed: () async {
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
await ok();
|
||
|
|
})
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
void showCommentDialog(BuildContext context, commentCallback(comment)) {
|
||
|
|
TextEditingController _comment = new TextEditingController();
|
||
|
|
showDialog(
|
||
|
|
context: context,
|
||
|
|
builder: (_) {
|
||
|
|
return AlertDialog(
|
||
|
|
shape: RoundedRectangleBorder(
|
||
|
|
borderRadius: BorderRadius.all(Radius.circular(32.0))),
|
||
|
|
content: Container(
|
||
|
|
width: 300.0,
|
||
|
|
height: 80.0,
|
||
|
|
child: Container(
|
||
|
|
child: TextFormField(
|
||
|
|
controller: _comment,
|
||
|
|
autofocus: false,
|
||
|
|
cursorColor: primaryColor,
|
||
|
|
maxLines: 3,
|
||
|
|
style: textStyle,
|
||
|
|
decoration: new InputDecoration(
|
||
|
|
labelText: "Comment",
|
||
|
|
labelStyle: labelStyle,
|
||
|
|
icon: Icon(
|
||
|
|
Icons.add_comment,
|
||
|
|
color: primaryColor,
|
||
|
|
),
|
||
|
|
enabledBorder: UnderlineInputBorder(
|
||
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||
|
|
focusedBorder: UnderlineInputBorder(
|
||
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||
|
|
),
|
||
|
|
validator: (value) {
|
||
|
|
if (value.isEmpty) {
|
||
|
|
return "Please enter comment";
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
actions: <Widget>[
|
||
|
|
FlatButton(
|
||
|
|
child: Text(
|
||
|
|
"Cancel",
|
||
|
|
style: labelStyle,
|
||
|
|
),
|
||
|
|
onPressed: () {
|
||
|
|
_comment.clear();
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
}),
|
||
|
|
FlatButton(
|
||
|
|
color: primaryColor,
|
||
|
|
child: Text("Submit",
|
||
|
|
style: TextStyle(
|
||
|
|
color: Colors.white, fontWeight: FontWeight.bold)),
|
||
|
|
onPressed: () {
|
||
|
|
commentCallback(_comment.text);
|
||
|
|
Navigator.of(context).pop();
|
||
|
|
})
|
||
|
|
],
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
Widget getStatus(String status) {
|
||
|
|
return status == "approved"
|
||
|
|
? Chip(
|
||
|
|
backgroundColor: Colors.green,
|
||
|
|
avatar: Icon(
|
||
|
|
Icons.check,
|
||
|
|
color: Colors.white,
|
||
|
|
size: 14,
|
||
|
|
),
|
||
|
|
label: Text(
|
||
|
|
status,
|
||
|
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
||
|
|
))
|
||
|
|
: status == "rejected"
|
||
|
|
? Chip(
|
||
|
|
backgroundColor: Colors.red,
|
||
|
|
avatar: Icon(
|
||
|
|
Icons.remove,
|
||
|
|
color: Colors.white,
|
||
|
|
size: 14,
|
||
|
|
),
|
||
|
|
label: Text(
|
||
|
|
status,
|
||
|
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
||
|
|
))
|
||
|
|
: status == "pending"
|
||
|
|
? Chip(
|
||
|
|
backgroundColor: Colors.blue,
|
||
|
|
avatar: Icon(
|
||
|
|
Icons.timelapse,
|
||
|
|
color: Colors.white,
|
||
|
|
size: 14,
|
||
|
|
),
|
||
|
|
label: Text(
|
||
|
|
status,
|
||
|
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
||
|
|
))
|
||
|
|
: Chip(
|
||
|
|
avatar: Icon(
|
||
|
|
Icons.check,
|
||
|
|
size: 14,
|
||
|
|
),
|
||
|
|
label: Text(status));
|
||
|
|
}
|
||
|
|
|
||
|
|
call(BuildContext context, String phone) {
|
||
|
|
showConfirmDialog(context, "contact.phone.confim", () => launch("tel:$phone"),
|
||
|
|
translationVariables: ["$phone"]);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> displayNotiContent(
|
||
|
|
BuildContext context, Noti.Notification noti) async {
|
||
|
|
if (!noti.seen) {
|
||
|
|
Provider.of<NotificationModel>(context, listen: false).seenID(noti.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
if (noti.itemType == "buyer") {
|
||
|
|
BuyerModel buyerModel = Provider.of<BuyerModel>(context, listen: false);
|
||
|
|
Buyer buyer = await buyerModel.getBuyer(noti.itemID);
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (context) => BuyerInfo(
|
||
|
|
buyer: buyer,
|
||
|
|
)),
|
||
|
|
);
|
||
|
|
} else if (noti.itemType == "announcement") {
|
||
|
|
AnnouncementModel announcementModel =
|
||
|
|
Provider.of<AnnouncementModel>(context, listen: false);
|
||
|
|
var announce = await announcementModel.getAnnouncement(noti.itemID);
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (context) => AnnouncementPage(announcement: announce)),
|
||
|
|
);
|
||
|
|
} else if (noti.itemType == "reg") {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(builder: (context) => MyRegisterationInfo()),
|
||
|
|
);
|
||
|
|
} else if (noti.itemType == "po") {
|
||
|
|
POSubmissionModel poModel =
|
||
|
|
Provider.of<POSubmissionModel>(context, listen: false);
|
||
|
|
var po = await poModel.getPO(noti.itemID);
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (context) => POSubmissionForm(
|
||
|
|
poSubmission: po,
|
||
|
|
)),
|
||
|
|
);
|
||
|
|
} else if (noti.itemType == "do") {
|
||
|
|
DOModel doModel = Provider.of<DOModel>(context, listen: false);
|
||
|
|
var _do = await doModel.getDO(noti.itemID);
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(builder: (context) => DOApproval(doSubmission: _do)),
|
||
|
|
);
|
||
|
|
} else if (noti.itemType == "price") {
|
||
|
|
Navigator.of(context)
|
||
|
|
.push(MaterialPageRoute(builder: (_) => ProductsList()));
|
||
|
|
} else if (noti.itemType == 'new_device_login') {
|
||
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (_) => LogList()));
|
||
|
|
} else if (noti.itemType == 'user') {
|
||
|
|
UserModel userModel = Provider.of<UserModel>(context, listen: false);
|
||
|
|
var user = await userModel.getUser(noti.itemID);
|
||
|
|
Navigator.of(context).push(MaterialPageRoute(
|
||
|
|
builder: (_) => UserEditor(
|
||
|
|
user: user,
|
||
|
|
viewOnly: true,
|
||
|
|
)));
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
log.warning("Error:$e \n ${noti.toString()}");
|
||
|
|
showMsgDialog(context, "Error", "Notification item not found!");
|
||
|
|
} finally {}
|
||
|
|
}
|