You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/uitl/utils_new.dart

597 lines
16 KiB
Dart

import 'dart:ui';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
Decoration appGradient = BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFFFDCA46F),
Color(0xFFFA47E5D),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
);
Color getColorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll('#', '');
if (hexColor.length == 6) {
hexColor = 'FF' + hexColor;
}
return Color(int.parse(hexColor, radix: 16));
}
Widget getPaymentMethods() {
return Container(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/images/new/payment/Mada.png", width: 40, height: 40),
Image.asset("assets/images/new/payment/tamara_en.png", width: 40, height: 40),
Image.asset("assets/images/new/payment/visa.png", width: 40, height: 40),
Image.asset("assets/images/new/payment/Mastercard.png", width: 50, height: 40),
Image.asset("assets/images/new/payment/Apple_Pay.png", width: 40, height: 40),
],
),
);
}
Widget getNoDataWidget(BuildContext context) {
return Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset('assets/images/new/not_found.svg', width: 110.0, height: 110.0),
Container(margin: EdgeInsets.only(top: 15.0), child: Text(TranslationBase.of(context).noResultFound, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFFBABABA)))),
],
),
),
);
}
spacerVertical(double v) {
return Container(
height: v,
width: double.infinity,
);
}
spacerHorizontal(double v) {
return Container(
height: v,
width: v,
);
}
spacer() {
return SizedBox(
height: 8,
);
}
Future navigateTo(context, page) async {
return await Navigator.push(context, MaterialPageRoute(builder: (context) => page));
}
// Future navigateToReplace(context, page) async {
// Navigator.pushReplacement(context, FadeRouteBuilder(page: page));
// }
InputDecoration txtField(String label) {
return new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
hintText: label,
hintStyle: TextStyle(color: Colors.grey),
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15, right: 15),
);
}
InputDecoration txtField3(String label) {
return new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
hintText: label,
disabledBorder: InputBorder.none,
counterText: "",
contentPadding: EdgeInsets.only(left: 5, right: 5),
);
}
InputDecoration txtFieldSearch(String label) {
return new InputDecoration(
border: InputBorder.none,
suffixIcon: Icon(Icons.clear),
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15, right: 15),
);
}
Widget circularAviator(
double s, {
Color bcColor,
Color brColor,
Color iconColor,
int borderWidth,
IconData icon,
double elevation = 4,
}) {
return Card(
shape: cardRadiusNew(2000),
color: Colors.transparent,
elevation: elevation,
child: Container(
width: s,
height: s,
decoration: containerColorRadiusBorderWidth(bcColor == null ? Colors.grey[200] : bcColor, 2000, brColor == null ? Colors.blueGrey[800] : brColor, borderWidth == null ? 2 : borderWidth),
child: Icon(
icon == null ? Icons.person : icon,
size: s / 1.7,
color: iconColor == null ? Colors.grey[800] : iconColor,
),
),
);
}
Widget circularImage(String im, double width, double height) {
return new Container(
width: 190.0,
height: 190.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage(im),
),
),
);
}
circularImage2(String im, double width, double height) {
return new Container(
width: width,
height: height,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage(im),
),
),
);
}
Widget mDivider(Color color) {
return Divider(
// width: double.infinity,
height: 1,
color: color,
);
}
Widget mFlex(int f) {
return Flexible(
flex: f,
child: Container(),
);
}
mOverlay(double op) {
return Opacity(
opacity: op,
child: Container(
color: Colors.black,
width: double.infinity,
height: double.infinity,
),
);
}
Widget mHeight(double h) {
return Container(
height: h,
);
}
Widget mWidth(double w) {
return Container(
width: w,
);
}
RoundedRectangleBorder buttonShape() {
return RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14.0),
);
}
Decoration containerRadiusWithGradient(double radius, {Color color1, Color color2}) {
return BoxDecoration(
borderRadius: BorderRadius.circular(radius),
gradient: LinearGradient(
colors: [
color1 ?? Color(0xFFF71787E),
color2 ?? Color(0xFFF2B353E),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
);
}
Decoration containerBottomRightRadiusWithGradient(double radius, {Color darkColor, Color lightColor}) {
return BoxDecoration(
borderRadius: BorderRadius.only(bottomRight: Radius.circular(radius)),
gradient: LinearGradient(
colors: [
darkColor == null ? Color(0xFFF2B353E) : darkColor,
lightColor == null ? Color(0xFFF71787E) : lightColor,
],
begin: Alignment.topCenter,
end: Alignment.bottomRight,
),
);
}
Decoration containerBottomRightRadiusWithGradientForAr(double radius, {Color darkColor, Color lightColor}) {
return BoxDecoration(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(radius)),
gradient: LinearGradient(
colors: [
lightColor == null ? Color(0xFFF71787E) : lightColor,
darkColor == null ? Color(0xFFF2B353E) : darkColor,
],
begin: Alignment.topCenter,
end: Alignment.bottomRight,
),
);
}
Decoration containerRadiusWithGradientServices(
double radius, {
Color darkColor,
Color lightColor,
bool isProduct = false,
bool prescriptionRequired = false,
bool isEnglish = true,
}) {
return BoxDecoration(
borderRadius: !isProduct || !prescriptionRequired
? BorderRadius.all(Radius.circular(radius))
: isEnglish
? BorderRadius.only(
topLeft: Radius.circular(26),
)
: BorderRadius.only(
topRight: Radius.circular(26),
),
gradient: LinearGradient(
colors: [
darkColor == null ? Color(0xFF2B353E) : darkColor,
lightColor == null ? Color(0xFF71787E) : lightColor,
],
begin: Alignment.centerRight,
end: Alignment.topLeft,
),
);
}
Decoration containerBottomRightRadiusWithGradientBorder(double radius, {Color darkColor, Color lightColor, Color borderColor = Colors.transparent, double w = 0}) {
return BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(radius)),
border: Border.all(
width: w, //
color: borderColor // <--- border width here
),
gradient: LinearGradient(
colors: [
darkColor == null ? Color(0xFFF2B353E) : darkColor,
lightColor == null ? Color(0xFFF71787E) : lightColor,
],
begin: Alignment.topCenter,
end: Alignment.bottomRight,
),
);
}
Decoration containerRadius(Color background, double radius) {
return BoxDecoration(
color: background,
boxShadow: [
BoxShadow(
color: Color(0xff000000).withOpacity(.05),
blurRadius: 27,
offset: Offset(0, -3),
),
],
border: Border.all(
width: 1, //
color: background // <--- border width here
),
borderRadius: BorderRadius.circular(radius),
);
}
Decoration containerColorRadiusBorder(Color background, double radius, Color color) {
return BoxDecoration(
color: background,
border: Border.all(
width: 1, //
color: color // <--- border width here
),
borderRadius: BorderRadius.circular(radius),
);
}
Decoration containerColorRadiusBorderWidth(Color background, double radius, Color color, double w) {
return BoxDecoration(
color: background,
border: Border.all(
width: w, //
color: color // <--- border width here
),
borderRadius: BorderRadius.circular(radius),
);
}
Decoration containerColorRadiusBorderWidthCircular(Color background, double radius, Color color, double w) {
return BoxDecoration(
color: background,
border: Border.all(
width: w, //
color: color // <--- border width here
),
// borderRadius: BorderRadius.circular(radius),
shape: BoxShape.circle,
);
}
Decoration containerColorRadiusRight(Color background, double radius) {
return BoxDecoration(
color: background,
borderRadius: BorderRadius.only(topRight: Radius.circular(radius), bottomRight: Radius.circular(radius)),
);
}
Decoration containerColorRadiusLeft(Color background, double radius) {
return BoxDecoration(
color: background,
borderRadius: BorderRadius.only(topLeft: Radius.circular(radius), bottomLeft: Radius.circular(radius)),
);
}
Decoration containerColorRadiusRightBorder(Color background, double radius, double w) {
return BoxDecoration(
color: background,
border: Border.all(
width: w, //
color: Colors.white // <--- border width here
),
borderRadius: BorderRadius.only(topRight: Radius.circular(radius), bottomRight: Radius.circular(radius)),
);
}
Decoration containerColorRadiusRightBorderc(Color background, double radius, double w, Color borderColor) {
return BoxDecoration(
color: background,
border: Border.all(
width: w, //
color: borderColor // <--- border width here
),
borderRadius: BorderRadius.circular(radius),
);
}
Decoration containerColorRadiusTop(Color color, double radius) {
return BoxDecoration(
color: color,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(radius),
topRight: Radius.circular(radius),
),
);
}
Decoration containerColorRadiusBottom(Color color, double radius) {
return BoxDecoration(
color: color,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(radius),
bottomRight: Radius.circular(radius),
),
);
}
Decoration containerColorRadiusLeftBorder(Color background, double radius, double w) {
return BoxDecoration(
color: background,
border: Border.all(
width: w, //
color: Colors.white // <--- border width here
),
borderRadius: BorderRadius.only(topLeft: Radius.circular(radius), bottomLeft: Radius.circular(radius)),
);
}
BoxDecoration cardRadius(double radius, {Color color, double elevation}) {
return BoxDecoration(
shape: BoxShape.rectangle,
color: color ?? Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(radius),
),
boxShadow: [
BoxShadow(
color: Color(0xff000000).withOpacity(.05),
//spreadRadius: 5,
blurRadius: elevation ?? 27,
offset: Offset(-2, 3),
),
],
);
}
ShapeBorder cardRadiusNew(double radius) {
return RoundedRectangleBorder(
side: BorderSide(color: Colors.transparent, width: 0),
borderRadius: BorderRadius.all(Radius.circular(radius)),
);
}
ShapeBorder cardRadiusTop(double radius) {
return RoundedRectangleBorder(
side: BorderSide(color: Colors.transparent, width: 0),
borderRadius: BorderRadius.only(topLeft: Radius.circular(radius), topRight: Radius.circular(radius)),
);
}
ShapeBorder cardRadiusTop2(double radius) {
return RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(radius), topRight: Radius.circular(radius)),
);
}
ShapeBorder cardRadiusBottom(double radius) {
return RoundedRectangleBorder(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(radius), bottomRight: Radius.circular(radius)),
);
}
ShapeBorder cardRadiusWithoutBorder(double radius) {
return RoundedRectangleBorder(
side: BorderSide(color: Colors.transparent, width: 1),
borderRadius: BorderRadius.circular(radius),
);
}
ShapeBorder cardRadiusWithBorder(double radius) {
return RoundedRectangleBorder(
side: BorderSide(color: Colors.grey, width: 1),
borderRadius: BorderRadius.circular(radius),
);
}
ShapeBorder cardRadiusBorder(double radius, double w) {
return RoundedRectangleBorder(
side: BorderSide(color: Colors.transparent, width: w),
borderRadius: BorderRadius.circular(radius),
);
}
// String properRound(double val, int places) {
// double mod = pow(10.0, places);
// double result = ((val * mod).round().toDouble() / mod);
// return result.toString();
// }
//
// double properRoundDouble(double val, int places) {
// double mod = pow(10.0, places);
// double result = ((val * mod).round().toDouble() / mod);
// return result;
// }
//var cardShape = RoundedRectangleBorder(
// side: BorderSide(color: Colors.white70, width: 1),
// borderRadius: BorderRadius.circular(10),
//);
//await Navigator.of(context).push(new MaterialPageRoute<dynamic>(
//builder: (BuildContext context) {
//return AdminTeamAvaluatePage(widget.competitionID, data);
//},
//));
//setState(() {});
Color getColor(String selectedColor) {
try {
if ("black" == selectedColor) {
return Colors.black;
} else if ("red" == selectedColor) {
return Colors.red;
} else if ("blueAccent" == selectedColor) {
return Colors.blueAccent;
} else if ("blue" == selectedColor) {
return Colors.blue;
} else if ("blueGrey" == selectedColor) {
return Colors.blueGrey;
} else if ("yellow" == selectedColor) {
return Colors.yellow;
} else if ("black54" == selectedColor) {
return Colors.black54;
} else if ("green" == selectedColor) {
return Colors.green;
} else if ("orange" == selectedColor) {
return Colors.orange;
} else if ("deepOrange" == selectedColor) {
return Colors.deepOrange;
} else {
return Colors.black;
}
} catch (e) {
return Colors.black;
}
}
TextAlign getTextAlign(String textAlign) {
try {
if (textAlign == "left") {
return TextAlign.left;
} else if (textAlign == "right") {
return TextAlign.right;
} else if (textAlign == "center") {
return TextAlign.center;
} else if (textAlign == "justify") {
return TextAlign.justify;
} else {
return TextAlign.left;
}
} catch (e) {
print("fffff " + e.toString());
return TextAlign.left;
}
}
FontWeight getFontWeight(String fontWeight) {
if (fontWeight == null) {
return FontWeight.normal;
} else if (fontWeight == "bold") {
return FontWeight.bold;
} else {
return FontWeight.normal;
}
}
FontStyle getFontStyle(String fontStyle) {
try {
if (fontStyle == null) {
return FontStyle.normal;
} else if (fontStyle == "italian") {
return FontStyle.italic;
} else {
return FontStyle.normal;
}
} catch (e) {
return FontStyle.normal;
}
}
bool timeCalculator(int startHour, int startMint, int endHour, int endMint) {
DateTime now = DateTime.now();
DateTime startDate = DateTime(now.year, now.month, now.day, startHour, startHour);
DateTime endDate = DateTime(now.year, now.month, now.day, endHour, endMint);
if (startDate.isBefore(now) && endDate.isAfter(now))
return true;
else
return false;
}