513 lines
17 KiB
Dart
513 lines
17 KiB
Dart
// ignore_for_file: deprecated_member_use
|
|
|
|
import 'package:fcs/domain/entities/user.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/localization/app_translations.dart';
|
|
import 'package:fcs/pages/main/model/language_model.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../widgets/label_widgets.dart';
|
|
|
|
final log = Logger('Util');
|
|
|
|
Future showMsgDialog(BuildContext context, String title, String msg) {
|
|
return showDialog(
|
|
context: context,
|
|
builder: (_) {
|
|
return AlertDialog(
|
|
title: Text(title),
|
|
content: Text(msg),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text(
|
|
"Close",
|
|
style: TextStyle(color: primaryColor),
|
|
),
|
|
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,
|
|
color: primaryColor,
|
|
),
|
|
),
|
|
content: Container(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
TextButton(
|
|
style: TextButton.styleFrom(
|
|
backgroundColor: Colors.grey[300],
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(5.0))),
|
|
child: Text(
|
|
AppTranslations.of(context)!.text('btn.cancel'),
|
|
style: Provider.of<LanguageModel>(context).isEng
|
|
? TextStyle(color: primaryColor)
|
|
: TextStyle(
|
|
fontFamily: 'Myanmar3', color: primaryColor),
|
|
),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
}),
|
|
SizedBox(
|
|
width: 0,
|
|
),
|
|
TextButton(
|
|
style: TextButton.styleFrom(
|
|
backgroundColor: primaryColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(5.0))),
|
|
child: Text(AppTranslations.of(context)!.text('btn.ok'),
|
|
style: Provider.of<LanguageModel>(context).isEng
|
|
? TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold)
|
|
: TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
fontFamily: 'Myanmar3')),
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
await ok();
|
|
})
|
|
],
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget getStatus(String status) {
|
|
return status == "Delivered"
|
|
? Text(status,
|
|
style: TextStyle(
|
|
color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold))
|
|
: 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 == "In progress"
|
|
? Text(
|
|
status,
|
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
|
)
|
|
: status == "Pickuped"
|
|
? Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
)
|
|
: status == "Pending" || status == "Rescheduled"
|
|
? Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Icon(Icons.schedule),
|
|
),
|
|
Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
)
|
|
],
|
|
)
|
|
: status == "Assigned"
|
|
? Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Icon(Icons.check),
|
|
),
|
|
Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
)
|
|
],
|
|
)
|
|
: status == "Canceled"
|
|
? Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
)
|
|
: status == "Delivered" || status == "Avaliable"
|
|
? Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: Colors.green, fontSize: 18),
|
|
)
|
|
: status == "Used"
|
|
? Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: Colors.red, fontSize: 18),
|
|
)
|
|
: status == "Paid"
|
|
? Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.all(8.0),
|
|
child: Icon(Icons.check),
|
|
),
|
|
Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight:
|
|
FontWeight.bold),
|
|
)
|
|
],
|
|
)
|
|
: Text(
|
|
status,
|
|
style: TextStyle(
|
|
color: primaryColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
);
|
|
}
|
|
|
|
call(BuildContext context, String phone) {
|
|
showConfirmDialog(context, "contact.phone.confim", () => launch("tel:$phone"),
|
|
translationVariables: [phone]);
|
|
}
|
|
|
|
Widget nameWidget(String name) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 10.0, top: 8),
|
|
child: Text(
|
|
name,
|
|
style: TextStyle(
|
|
color: Colors.black87, fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget phoneWidget(BuildContext context, String phone) {
|
|
return Container(
|
|
padding: EdgeInsets.only(top: 10),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Icon(Icons.phone),
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
child: labeledText(context, phone, "user.phone"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget fcsInput(String label, IconData iconData,
|
|
{required TextEditingController controller,
|
|
required String value,
|
|
bool autoFocus = false,
|
|
TextInputType? textInputType}) {
|
|
return TextFormField(
|
|
initialValue: value,
|
|
controller: controller,
|
|
cursorColor: primaryColor,
|
|
maxLines: null,
|
|
minLines: 1,
|
|
autofocus: autoFocus,
|
|
keyboardType: textInputType,
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
labelText: label,
|
|
labelStyle: TextStyle(fontSize: 16, color: Colors.grey),
|
|
filled: true,
|
|
icon: Icon(
|
|
iconData,
|
|
color: primaryColor,
|
|
),
|
|
focusedBorder: UnderlineInputBorder(
|
|
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
|
|
));
|
|
}
|
|
|
|
Widget fcsInputReadOnly(String label, IconData iconData,
|
|
{required TextEditingController controller, required String value}) {
|
|
return TextFormField(
|
|
initialValue: value,
|
|
controller: controller,
|
|
cursorColor: primaryColor,
|
|
maxLines: null,
|
|
minLines: 1,
|
|
readOnly: true,
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
border: InputBorder.none,
|
|
labelText: label,
|
|
labelStyle: TextStyle(fontSize: 16, color: Colors.grey),
|
|
filled: true,
|
|
icon: Icon(
|
|
iconData,
|
|
color: primaryColor,
|
|
),
|
|
));
|
|
}
|
|
|
|
Widget fcsDropDown(String label, IconData iconData,
|
|
{required TextEditingController controller}) {
|
|
return Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
child: Icon(iconData),
|
|
),
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 50.0,
|
|
child: Row(children: <Widget>[
|
|
Expanded(child: _dropDown()),
|
|
]),
|
|
)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _dropDown() {
|
|
return DropdownButton<String>(
|
|
value: "Ko Nge",
|
|
icon: Icon(Icons.arrow_downward),
|
|
iconSize: 24,
|
|
elevation: 16,
|
|
// style: TextStyle(color: Colors.deepPurple),
|
|
underline: Container(
|
|
height: 2,
|
|
color: primaryColor,
|
|
),
|
|
onChanged: (String? newValue) {},
|
|
items: <String>['Ko Nge', 'Two', 'Free', 'Four']
|
|
.map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value),
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
|
|
Widget fcsButton(BuildContext context, String text,
|
|
{Function? callack, IconData? iconData}) {
|
|
var languageModel = Provider.of<LanguageModel>(context);
|
|
|
|
var style = languageModel.isEng
|
|
? TextStyle(
|
|
fontSize: 16.0, color: Colors.white, fontWeight: FontWeight.bold)
|
|
: TextStyle(
|
|
fontSize: 16.0,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
fontFamily: "Myanmar3");
|
|
|
|
return Container(
|
|
padding: EdgeInsets.only(left: 10, right: 10, top: 10),
|
|
child: SizedBox(
|
|
height: 45.0,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
elevation: 0,
|
|
backgroundColor: primaryColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(3)))),
|
|
onPressed: callack == null ? null : () => callack(),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
iconData == null
|
|
? Container()
|
|
: Icon(
|
|
iconData,
|
|
color: Colors.white,
|
|
),
|
|
SizedBox(
|
|
width: 15,
|
|
),
|
|
Text(text, style: style),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String getLocalString(BuildContext context, String key) {
|
|
return AppTranslations.of(context)!.text(key);
|
|
}
|
|
|
|
void showToast(GlobalKey key, String text) {
|
|
final ScaffoldMessengerState scaffold =
|
|
key.currentState as ScaffoldMessengerState;
|
|
scaffold.showSnackBar(
|
|
SnackBar(
|
|
content: Text(text),
|
|
backgroundColor: secondaryColor,
|
|
duration: Duration(seconds: 1),
|
|
),
|
|
);
|
|
}
|
|
|
|
bool hasUnicode(String text) {
|
|
final int maxBits = 128;
|
|
List<int> unicodeSymbols =
|
|
text.codeUnits.where((ch) => ch > maxBits).toList();
|
|
return unicodeSymbols.isNotEmpty;
|
|
}
|
|
|
|
String removeTrailingZeros(double number) {
|
|
String result = number.toString();
|
|
result = result.indexOf('.') > 0
|
|
? result.replaceAll(RegExp(r"([.]*0)(?!.*\d)"), "")
|
|
: result;
|
|
return result;
|
|
}
|
|
|
|
bool isValidEmail(String email) {
|
|
// Define a regular expression for validating an email
|
|
final emailRegex = RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$');
|
|
|
|
// Check if the email matches the pattern
|
|
return emailRegex.hasMatch(email);
|
|
}
|
|
|
|
String capitalizeFirstLetter(String text) {
|
|
if (text.isEmpty) return text;
|
|
return text[0].toUpperCase() + text.substring(1);
|
|
}
|
|
|
|
Widget userSearchBox(BuildContext context,
|
|
{required String lableKey,
|
|
IconData? icon,
|
|
User? user,
|
|
Function()? onSearch,
|
|
MainAxisAlignment rowMainAxisAlignment = MainAxisAlignment.start}) {
|
|
return Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: rowMainAxisAlignment,
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 2),
|
|
child:
|
|
LocalText(context, lableKey, color: labelColor, fontSize: 15),
|
|
)),
|
|
IconButton(
|
|
icon: Icon(Icons.search, color: Colors.black),
|
|
onPressed: onSearch),
|
|
],
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
right: 15,
|
|
),
|
|
child: user != null && user.fcsID != ""
|
|
? Icon(icon, color: primaryColor)
|
|
: const SizedBox(),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(user?.name ?? ''),
|
|
Text(user?.fcsID ?? '',
|
|
style: TextStyle(fontSize: 13, color: labelColor)),
|
|
Text(user?.phoneNumber ?? '',
|
|
style: TextStyle(fontSize: 13, color: labelColor))
|
|
],
|
|
))
|
|
],
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget userDisplayBox(BuildContext context,
|
|
{required String lableKey, IconData? icon, String? name, String? fcsID}) {
|
|
return fcsID != null && fcsID != ""
|
|
? Padding(
|
|
padding: const EdgeInsets.only(top: 8.0, bottom: 8),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 15),
|
|
child: Icon(icon, color: primaryColor)),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
LocalText(context, lableKey,
|
|
color: Colors.black54, fontSize: 15),
|
|
InkWell(
|
|
onTap: null,
|
|
child: Text(
|
|
name ?? '',
|
|
style: TextStyle(
|
|
shadows: [
|
|
Shadow(color: linkColor, offset: Offset(0, -2))
|
|
],
|
|
color: Colors.transparent,
|
|
decoration: TextDecoration.underline,
|
|
decorationColor: linkColor),
|
|
),
|
|
),
|
|
Text(fcsID,
|
|
style: TextStyle(fontSize: 13, color: labelColor))
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: const SizedBox();
|
|
}
|