initial code
This commit is contained in:
11
lib/utils/constants/assets_constant.dart
Normal file
11
lib/utils/constants/assets_constant.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
class APPASSETS {
|
||||
static const String svgBaseUrl = "assets/images/svgs";
|
||||
static const String pngBaseUrl = "assets/images/pngs";
|
||||
|
||||
//SVG
|
||||
static const String back = "$svgBaseUrl/back.svg";
|
||||
//PNG
|
||||
static const String splashImagePNG = "$pngBaseUrl/splash.png";
|
||||
static const String onBoardMan = "$pngBaseUrl/onboard_man.png";
|
||||
static const String placeHolder = '$pngBaseUrl/placeHolder.png';
|
||||
}
|
||||
15
lib/utils/constants/color_constant.dart
Normal file
15
lib/utils/constants/color_constant.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/utils/extensions/color_ex.dart';
|
||||
|
||||
class APPCOLOR {
|
||||
static Color appGreen = HexColor('228B22');
|
||||
static Color lightGreen = HexColor('00d267');
|
||||
static Color balck1A1A1A = HexColor('1A1A1A');
|
||||
static Color black333333 = HexColor('333333');
|
||||
static Color grey666666 = HexColor('666666');
|
||||
static Color whiteFBFEFB = HexColor('FBFEFB');
|
||||
static Color borderColor = HexColor('181616');
|
||||
static Color gery48514D = HexColor('48514D');
|
||||
static Color lightGreyF4F5F5 = HexColor('F7FDF7');
|
||||
static Color bgGrey = Colors.grey.withOpacity(0.0500);
|
||||
}
|
||||
5
lib/utils/constants/globle_variable.dart
Normal file
5
lib/utils/constants/globle_variable.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GlobalVariable{
|
||||
static final globalScaffoldKey = GlobalKey<NavigatorState>();
|
||||
}
|
||||
314
lib/utils/constants/shared_pref_utils.dart
Normal file
314
lib/utils/constants/shared_pref_utils.dart
Normal file
@@ -0,0 +1,314 @@
|
||||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
// Shared preference for the app to store data locally
|
||||
class SharedPrefUtils {
|
||||
SharedPrefUtils._();
|
||||
|
||||
static String? _token;
|
||||
static String? _resetToken;
|
||||
static String? _refreshToken;
|
||||
static const String PROFILE_PIC = "profile_pic";
|
||||
static const String BADGE_URL = "badge_url";
|
||||
static String USER_NAME = "username";
|
||||
static const String INS_RANDOM = "ins_random";
|
||||
static const String INS_NearBy = "ins_nearby";
|
||||
static const String USER_ID = "user_id";
|
||||
static String PHONE = "phone";
|
||||
static const String BACK_STATUS = "back_status";
|
||||
static const String HAND_OF_ACTION = "hand_of_action";
|
||||
static const String VERIFIED_USER = "verified_user";
|
||||
static const String KEY_TOKEN = "KEY_TOKEN";
|
||||
static const String IS_PROFILE = "is_profile";
|
||||
static const String IS_FRESH_INSTALL = "is_fresh_install";
|
||||
static const String LAST_LOCATION = "LAST_LOCATION";
|
||||
static const String COUNTRY_CODE = "COUNTRY_CODE";
|
||||
static const String SELECTED_PROFILE = "selected_profile";
|
||||
static const String CITY = "city";
|
||||
static const String IS_SUBSCRIPTION_PURCHASE = "IS_SUBSCRIPTION_PURCHASE";
|
||||
static const String FIRST_NAME = "FIRST_NAME";
|
||||
static const String LAST_NAME = "FIRST_NAME";
|
||||
static const String EMAIL = "EMAIL";
|
||||
static const String PASSWORD = "PASSWORD";
|
||||
static const String RESET_TOKEN = "RESET_TOKEN";
|
||||
static const String STORE_ID = "STORE_ID";
|
||||
static const String REFRESH_TOKEN = "REFRESH_TOKEN";
|
||||
|
||||
/// Set bearer authorization token
|
||||
static Future<bool> setToken({required String authToken}) {
|
||||
_token = authToken;
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(KEY_TOKEN, authToken));
|
||||
}
|
||||
|
||||
static Future<bool> setRefreshToken({required String refresh_token}) {
|
||||
_refreshToken = refresh_token;
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(REFRESH_TOKEN, refresh_token));
|
||||
}
|
||||
|
||||
static Future<bool> setStoreId({required String storeId}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(STORE_ID, storeId));
|
||||
}
|
||||
|
||||
static Future<String?> getStoreId() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
_token = sp.getString(STORE_ID);
|
||||
return _token;
|
||||
}
|
||||
|
||||
static Future<bool> setResetToken({required String resetToken}) {
|
||||
resetToken = resetToken;
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(RESET_TOKEN, resetToken));
|
||||
}
|
||||
|
||||
static Future<bool> setFistName({required String firstName}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(FIRST_NAME, firstName));
|
||||
}
|
||||
|
||||
static Future<bool> setLastName({required String LastName}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(LAST_NAME, LastName));
|
||||
}
|
||||
|
||||
static Future<bool> setEmail({required String email}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(EMAIL, email));
|
||||
}
|
||||
|
||||
static Future<bool> setPassWord({required String password}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(PASSWORD, password));
|
||||
}
|
||||
|
||||
static Future<bool> setPhone({required int phone}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setInt(PHONE, phone));
|
||||
}
|
||||
|
||||
static Future<bool> getBackPopStatus() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(BACK_STATUS) ?? true;
|
||||
}
|
||||
|
||||
static Future<bool> setBackPopStatus(bool status) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setBool(BACK_STATUS, status));
|
||||
}
|
||||
|
||||
/// Get bearer authorization token
|
||||
static Future<String?> getToken() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
_token = sp.getString(KEY_TOKEN);
|
||||
return _token;
|
||||
}
|
||||
|
||||
static Future<String?> getRefreshToken() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
_refreshToken = sp.getString(REFRESH_TOKEN);
|
||||
return _refreshToken;
|
||||
}
|
||||
|
||||
static Future<String?> getResetToken() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
_resetToken = sp.getString(RESET_TOKEN);
|
||||
return _resetToken;
|
||||
}
|
||||
|
||||
static Future<bool> setIsSubscriptionPurchase(bool value) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setBool(IS_SUBSCRIPTION_PURCHASE, value));
|
||||
}
|
||||
|
||||
///Set availability of user profile
|
||||
static Future<bool> setIsUserProfileUpdated({required bool isUpdated}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setBool(IS_PROFILE, isUpdated));
|
||||
}
|
||||
|
||||
/// Get availability of user profile
|
||||
static Future<bool> isUserProfileUpdated() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(IS_PROFILE) ?? false;
|
||||
}
|
||||
|
||||
///Set is fresh install
|
||||
static Future<bool> setFreshInstall({required bool isFresh}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setBool(IS_FRESH_INSTALL, isFresh));
|
||||
}
|
||||
|
||||
/// Get is Fresh install
|
||||
static Future<bool> isFreshInstall() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(IS_FRESH_INSTALL) ?? true;
|
||||
}
|
||||
|
||||
static Future<int> getPhone() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getInt(PHONE) ?? 0;
|
||||
}
|
||||
|
||||
/// Get Selected profile, will be used
|
||||
static Future<String?> getSelectedProfile() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(SELECTED_PROFILE) ;
|
||||
}
|
||||
|
||||
/// Get is Fresh install
|
||||
/// Set last location of the user
|
||||
static setLatLongUserPosition(String location) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setString(LAST_LOCATION, location);
|
||||
}
|
||||
|
||||
/// Get last location of the user
|
||||
static Future<String?> getLatLongUserPosition() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(LAST_LOCATION);
|
||||
}
|
||||
|
||||
/// Get country code of the user
|
||||
static Future<String?> getCountryCode() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(COUNTRY_CODE);
|
||||
}
|
||||
|
||||
static setCountryCode(String countryCode) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setString(COUNTRY_CODE, countryCode);
|
||||
}
|
||||
|
||||
/// Set Selected profile, will be used
|
||||
static Future setSelectedProfile(String profileName) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setString(SELECTED_PROFILE, profileName);
|
||||
}
|
||||
|
||||
///Set profile url
|
||||
static Future<bool> setUserId({required String id}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(USER_ID, id));
|
||||
}
|
||||
|
||||
// /// Set Selected display name, will be used
|
||||
// static Future setUsername(String displayName) async {
|
||||
// final sp = await SharedPreferences.getInstance();
|
||||
// sp.setString(USER_NAME, displayName);
|
||||
// }
|
||||
|
||||
/// Set Selected display name, will be used
|
||||
static Future setUsername({required String displayName}) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setString(USER_NAME, displayName);
|
||||
}
|
||||
|
||||
static Future setRandomInstruction({required bool status}) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setBool(INS_RANDOM, status);
|
||||
}
|
||||
|
||||
static Future setNerarByInstruction({required bool status}) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setBool(INS_NearBy, status);
|
||||
}
|
||||
|
||||
/// Get username
|
||||
///
|
||||
///
|
||||
|
||||
static Future<String> getFirstName() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
|
||||
final firstName = sp.getString(FIRST_NAME);
|
||||
print("lkjhdsgkhfdkjg ${sp.getString(FIRST_NAME)}");
|
||||
|
||||
return firstName!;
|
||||
}
|
||||
|
||||
static Future<String> getLastName() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(LAST_NAME) ?? "";
|
||||
}
|
||||
|
||||
static Future<String> getEmail() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(EMAIL) ?? "";
|
||||
}
|
||||
|
||||
static Future<String> getPassword() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(PASSWORD) ?? "";
|
||||
}
|
||||
|
||||
static Future<String> getUsername() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(USER_NAME) ?? "";
|
||||
}
|
||||
|
||||
static Future<bool> getRandomInstruction() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(INS_RANDOM) ?? true;
|
||||
}
|
||||
|
||||
static Future<bool> getNerarByInstruction() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getBool(INS_NearBy) ?? true;
|
||||
}
|
||||
|
||||
///Set profile url
|
||||
static Future<bool> setProfilePicUrl({required String profileUrl}) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(PROFILE_PIC, profileUrl));
|
||||
}
|
||||
|
||||
/// Get profile url
|
||||
static Future<String> getProfilePicUrl() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(PROFILE_PIC) ?? "";
|
||||
}
|
||||
|
||||
/// Get profile url
|
||||
static Future<String> getBadgeUrl() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(BADGE_URL) ?? "";
|
||||
}
|
||||
|
||||
static Future setBadgeUrl({required String url}) async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.setString(BADGE_URL, url);
|
||||
}
|
||||
|
||||
/// Get profile url
|
||||
static Future<String> getUserId() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(USER_ID) ?? "";
|
||||
}
|
||||
|
||||
//Back Popup
|
||||
|
||||
static Future setCity(String city) {
|
||||
return SharedPreferences.getInstance()
|
||||
.then((sp) async => await sp.setString(CITY, city));
|
||||
}
|
||||
|
||||
static Future<String> getCity() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
return sp.getString(CITY) ?? "";
|
||||
}
|
||||
|
||||
/// Clear all preferences
|
||||
static Future<void> clear() async {
|
||||
final sp = await SharedPreferences.getInstance();
|
||||
sp.getKeys().forEach((key) async {
|
||||
if (key != IS_FRESH_INSTALL) {
|
||||
await sp.remove(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
19
lib/utils/constants/string_constant.dart
Normal file
19
lib/utils/constants/string_constant.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
class APPSTRING {
|
||||
//title
|
||||
static const String enterYourMobileNumber = "Enter Your Mobile Number";
|
||||
static const String whatYourPhoneNumber = "What's your phone number?";
|
||||
static const String codeSentText = "A code will be send to verify your phone number";
|
||||
|
||||
static const String enterVerificationCode = "Enter Verification Code";
|
||||
static const String enterCode = "Enter the 6-digit code sent to you at ********8902";
|
||||
static const String pleaseEnterYourFullName = "Please Enter Your Full Name";
|
||||
|
||||
//hint
|
||||
static const String phoneNumberHint = "Phone Number";
|
||||
static const String fullNameHint = "Full Name";
|
||||
|
||||
//button
|
||||
static const String verifyButton = "Verify";
|
||||
static const String continueBtn = "Continue";
|
||||
static const String appName = "Customer App";
|
||||
}
|
||||
15
lib/utils/extensions/color_ex.dart
Normal file
15
lib/utils/extensions/color_ex.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HexColor extends Color {
|
||||
static int _getColorFromHex(String hexColor) {
|
||||
hexColor = hexColor.toUpperCase().replaceAll("#", "");
|
||||
if (hexColor.length == 6) {
|
||||
hexColor = "FF$hexColor";
|
||||
}
|
||||
return int.parse(hexColor, radix: 16);
|
||||
}
|
||||
|
||||
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
|
||||
}
|
||||
76
lib/utils/extensions/common_utils.dart
Normal file
76
lib/utils/extensions/common_utils.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:grocery_app/utils/constants/globle_variable.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
/// Hides soft keyboard if already shown
|
||||
///
|
||||
enum SnackType {
|
||||
success,
|
||||
alert,
|
||||
error
|
||||
}
|
||||
|
||||
|
||||
void hideKeyBoard() {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
|
||||
|
||||
/// Show snackbar
|
||||
void showSnackBar(
|
||||
{ BuildContext ?context,
|
||||
required String message,
|
||||
SnackType snackType = SnackType.success,
|
||||
bool canDismiss = true,
|
||||
bool sticky = false,
|
||||
SnackBarBehavior behaviour = SnackBarBehavior.floating,
|
||||
}) {
|
||||
//if (!context?.mounted??) return;
|
||||
//Clear snack bars
|
||||
ScaffoldMessenger.of(context??GlobalVariable.globalScaffoldKey.currentContext!).clearSnackBars();
|
||||
// Snack bar
|
||||
final snackBar = SnackBar(
|
||||
behavior: behaviour,
|
||||
padding: EdgeInsets.zero,
|
||||
elevation: 0,
|
||||
content: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 8.h),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors:snackType==SnackType.success? const [
|
||||
Color(0xFF61B15A),
|
||||
Color(0xFF6ABE8B)
|
||||
]:snackType==SnackType.alert?
|
||||
const [
|
||||
Color(0xFFFF8906),
|
||||
Color(0xFFFFA745),
|
||||
]:
|
||||
const [
|
||||
Colors.red,
|
||||
Colors.redAccent,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
message,
|
||||
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
duration: sticky ? const Duration(days: 365) : const Duration(seconds: 3),
|
||||
dismissDirection:
|
||||
canDismiss ? DismissDirection.down : DismissDirection.none,
|
||||
);
|
||||
|
||||
// Find the ScaffoldMessenger in the widget tree
|
||||
// and use it to show a SnackBar.
|
||||
ScaffoldMessenger.of(context??GlobalVariable.globalScaffoldKey.currentContext!).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
|
||||
26
lib/utils/extensions/datehelper_ex.dart
Normal file
26
lib/utils/extensions/datehelper_ex.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String dateFormatter = 'MMMM dd, y';
|
||||
|
||||
extension DateHelper on DateTime
|
||||
{
|
||||
String formatDate() {
|
||||
final formatter = DateFormat(dateFormatter);
|
||||
return formatter.format(this);
|
||||
}
|
||||
|
||||
bool isSameDate(DateTime other) {
|
||||
return year == other.year && month == other.month && day == other.day;
|
||||
}
|
||||
|
||||
int getDifferenceInDaysWithNow() {
|
||||
final now = DateTime.now();
|
||||
return now.difference(this).inDays;
|
||||
}
|
||||
}
|
||||
|
||||
extension TimeOfDayExt on TimeOfDay {
|
||||
/// note: 'hour' is in 24-hour format
|
||||
double toDouble() => hour + minute / 60.0;
|
||||
}
|
||||
54
lib/utils/extensions/decoration_ex.dart
Normal file
54
lib/utils/extensions/decoration_ex.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/utils/constants/color_constant.dart';
|
||||
|
||||
extension CommonInputDecoration on InputDecoration {
|
||||
InputDecoration customRoundedTextFieldDecoration(String hint, Widget? prefix, Widget? suffix, TextStyle hintStyle) {
|
||||
var returnResult = InputDecoration(
|
||||
hintText: hint,
|
||||
labelText: hint,
|
||||
alignLabelWithHint: false,
|
||||
suffixIcon: suffix,
|
||||
suffixIconConstraints: const BoxConstraints(minWidth: 25, maxWidth: 25, maxHeight: 25, minHeight: 25),
|
||||
contentPadding: const EdgeInsets.only(top: 10, right: 10, bottom: 10, left: 10),
|
||||
prefix: prefix,
|
||||
constraints: const BoxConstraints(maxHeight: 60, minHeight: 60),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
labelStyle: hintStyle,
|
||||
hintStyle: hintStyle,
|
||||
isCollapsed: true,
|
||||
fillColor: APPCOLOR.whiteFBFEFB,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
borderSide: BorderSide(
|
||||
color: APPCOLOR.borderColor.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
counterText: "",
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
borderSide: BorderSide(
|
||||
color: APPCOLOR.borderColor.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
borderSide: const BorderSide(
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
borderSide: BorderSide(
|
||||
color: APPCOLOR.borderColor.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
disabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
borderSide: BorderSide(
|
||||
color: APPCOLOR.borderColor.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
);
|
||||
return returnResult;
|
||||
}
|
||||
}
|
||||
338
lib/utils/extensions/extensions.dart
Normal file
338
lib/utils/extensions/extensions.dart
Normal file
@@ -0,0 +1,338 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
extension ResponsiveExt on BuildContext {
|
||||
/// Returns true if the current running device is a mobile device
|
||||
bool get isMobile => MediaQuery.of(this).size.shortestSide < 600;
|
||||
}
|
||||
|
||||
extension IntExt on int {
|
||||
String formatAsK() {
|
||||
if (this >= 1000000) {
|
||||
return this % 1000000 == 0
|
||||
? '${(this / 1000000).toStringAsFixed(0)}M'
|
||||
: '${(this / 1000000).toStringAsFixed(1)}M';
|
||||
} else if (this >= 1000) {
|
||||
return this % 1000 == 0
|
||||
? '${(this / 1000).toStringAsFixed(0)}K'
|
||||
: '${(this / 1000).toStringAsFixed(1)}K';
|
||||
}
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
extension ThemeExt on BuildContext {
|
||||
/// Theme extensions
|
||||
TextStyle get titleStyle => GoogleFonts.nunito(
|
||||
color: appColor.blackColor, fontSize: 16.sp, fontWeight: FontWeight.w400);
|
||||
|
||||
TextStyle get titleStyleRegular => GoogleFonts.nunito(
|
||||
color: appColor.blackColor, fontSize: 19.sp, fontWeight: FontWeight.w600);
|
||||
|
||||
TextStyle get subTitleStyle => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: appColor.blackColor,
|
||||
fontSize: 18.sp,
|
||||
);
|
||||
TextStyle get buttonTestStyle => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: appColor.blackColor,
|
||||
fontSize: 14.sp,
|
||||
);
|
||||
|
||||
TextStyle get subTitleTextStyle => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w400,
|
||||
color: appColor.greyColor,
|
||||
fontSize: 16.sp,
|
||||
);
|
||||
TextStyle get subTitleTextStyleBloack => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: appColor.blackColor,
|
||||
fontSize: 14.sp,
|
||||
);
|
||||
|
||||
TextStyle get subTitleTxtStyleblack => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w400,
|
||||
color: appColor.blackColor,
|
||||
fontSize: 13.sp,
|
||||
);
|
||||
|
||||
TextStyle get subTitleTxtStyle => GoogleFonts.nunito(
|
||||
fontWeight: FontWeight.w400,
|
||||
color: appColor.greyColor,
|
||||
fontSize: 13.sp,
|
||||
);
|
||||
|
||||
TextStyle get bodyTxtStyle => GoogleFonts.chivo(
|
||||
fontSize: 14.sp, fontWeight: FontWeight.w400, color: appColor.blackColor);
|
||||
|
||||
TextStyle get bodyTxtStyleTwo => GoogleFonts.chivo(
|
||||
fontSize: 13.sp,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: appColor.blackColor,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: appColor.primary);
|
||||
|
||||
TextStyle get smallTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 10.sp,
|
||||
);
|
||||
|
||||
TextStyle get smallTxtStyleBold => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 10.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get titleTextStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 16.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get cardTitleStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 13.76.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get cardTitleStyleWhite => GoogleFonts.chivo(
|
||||
color: appColor.whiteColor,
|
||||
fontSize: 13.76.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get dropdownBodyTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 14.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get ratingTextStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 40.sp,
|
||||
fontWeight: FontWeight.w700,
|
||||
);
|
||||
|
||||
TextStyle get noReviewYetTextStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 33.sp,
|
||||
fontWeight: FontWeight.w700,
|
||||
);
|
||||
|
||||
TextStyle get dropdownTitleTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 13.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get yourTicketTextStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 13.5.sp,
|
||||
fontWeight: FontWeight.bold,
|
||||
);
|
||||
|
||||
TextStyle get priceBodyTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 16.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get orderDetailsHeadingTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.blackColor,
|
||||
fontSize: 18.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get buttonTxtStyle => GoogleFonts.chivo(
|
||||
color: appColor.whiteColor,
|
||||
fontSize: 15.59.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get bottomNavTextStyle => GoogleFonts.chivo(
|
||||
fontSize: 9.sp,
|
||||
color: appColor.greyColor500,
|
||||
fontWeight: FontWeight.w400,
|
||||
);
|
||||
|
||||
TextStyle get headingTextStyle => GoogleFonts.chivo(
|
||||
fontSize: 20.sp,
|
||||
color: appColor.blackColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get mainHeadingTextStyle => GoogleFonts.chivo(
|
||||
fontSize: 35.sp,
|
||||
color: appColor.blackColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
);
|
||||
|
||||
TextStyle get orderConfirmHeadingTextStyle => GoogleFonts.chivo(
|
||||
fontSize: 28.sp,
|
||||
color: appColor.blackColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
}
|
||||
|
||||
/// Build context extensions
|
||||
extension ContextExtension on BuildContext {
|
||||
void to({required Widget screen}) {
|
||||
Navigator.push(this, MaterialPageRoute(builder: (context) => screen));
|
||||
}
|
||||
|
||||
///Pops all screen until last screen then replaces it with the required screen
|
||||
void clearAndPush({required String routePath, Object? args}) {
|
||||
while (GoRouter.of(this).canPop()) {
|
||||
GoRouter.of(this).pop();
|
||||
}
|
||||
GoRouter.of(this).pushReplacement(routePath, extra: args);
|
||||
}
|
||||
|
||||
/// Get color scheme
|
||||
ColorScheme get appColor => Theme.of(this).colorScheme;
|
||||
|
||||
/// Get current height of the screen
|
||||
double get height => MediaQuery.of(this).size.height;
|
||||
|
||||
/// Get current height of the screen
|
||||
double get width => MediaQuery.of(this).size.width;
|
||||
|
||||
/// Provides safe context
|
||||
BuildContext? getSafeContext() {
|
||||
if (mounted) {
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// show global loader
|
||||
void showLoader({bool show = true}) {
|
||||
if (mounted) {
|
||||
if (show) {
|
||||
loaderOverlay.show();
|
||||
} else {
|
||||
loaderOverlay.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DateTimeExtension on DateTime? {
|
||||
bool? isAfterOrEqualTo(DateTime dateTime) {
|
||||
final date = this;
|
||||
if (date != null) {
|
||||
final isAtSameMomentAs = dateTime.isAtSameMomentAs(date);
|
||||
return isAtSameMomentAs | date.isAfter(dateTime);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String getFormattedDate({String pattern = "dd-mm-yyyy"}) {
|
||||
if (this != null) {
|
||||
return DateFormat(pattern).format(this!.toLocal());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool? isBeforeOrEqualTo(DateTime dateTime) {
|
||||
final date = this;
|
||||
if (date != null) {
|
||||
final isAtSameMomentAs = dateTime.isAtSameMomentAs(date);
|
||||
return isAtSameMomentAs | date.isBefore(dateTime);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool? isBetween(DateTime fromDateTime, DateTime toDateTime) {
|
||||
final date = this;
|
||||
if (date != null) {
|
||||
final isAfter = date.isAfterOrEqualTo(fromDateTime) ?? false;
|
||||
final isBefore = date.isBeforeOrEqualTo(toDateTime) ?? false;
|
||||
return isAfter && isBefore;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Color scheme extensions
|
||||
|
||||
extension ColorExtension on String {
|
||||
toColor() {
|
||||
var hexColor = this.replaceAll("#", "");
|
||||
if (hexColor.length == 6) {
|
||||
hexColor = "FF$hexColor";
|
||||
}
|
||||
if (hexColor.length == 8) {
|
||||
return Color(int.parse("0x$hexColor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ColorExt on ColorScheme {
|
||||
Color get blackColor =>
|
||||
brightness == Brightness.light ? const Color(0xff1A1A1A) : Colors.white38;
|
||||
|
||||
Color get greyColor =>
|
||||
brightness == Brightness.light ? const Color(0xff666666) : Colors.white30;
|
||||
|
||||
Color get greyColor500 =>
|
||||
brightness == Brightness.light ? Color(0xff6F6B7D) : Colors.white30;
|
||||
|
||||
Color get greyColor400 =>
|
||||
brightness == Brightness.light ? Colors.grey.shade400 : Colors.white30;
|
||||
|
||||
Color get greyColor200 =>
|
||||
brightness == Brightness.light ? Colors.grey.shade200 : Colors.white12;
|
||||
|
||||
Color get greyColor300 =>
|
||||
brightness == Brightness.light ? Colors.grey.shade300 : Colors.white12;
|
||||
|
||||
Color get greyColor100 =>
|
||||
brightness == Brightness.light ? Colors.grey.shade100 : Colors.white12;
|
||||
|
||||
Color get greyColor50 =>
|
||||
brightness == Brightness.light ? Color(0xffF8F8F8) : Colors.white12;
|
||||
|
||||
Color get lightBlackColor =>
|
||||
brightness == Brightness.light ? Colors.black26 : Colors.white30;
|
||||
|
||||
Color get whiteColor =>
|
||||
brightness == Brightness.light ? Colors.white : Colors.black;
|
||||
|
||||
Color get backgroundColor =>
|
||||
brightness == Brightness.dark ? const Color(0xFF0F0E17) : Colors.white;
|
||||
|
||||
Color get transparent => Colors.transparent;
|
||||
|
||||
Color get redColor => Colors.red;
|
||||
|
||||
Color get primarycolor => Color(0xff228B22);
|
||||
|
||||
// Color get reviewColor =>
|
||||
// brightness == Brightness.dark ? Colors.green : const Color(0xff006D60);
|
||||
//
|
||||
// Color get successColor =>
|
||||
// brightness == Brightness.light ? Colors.green : Colors.green;
|
||||
//
|
||||
// Color get chatTextColor =>
|
||||
// brightness == Brightness.light ? Colors.blue : Colors.lightBlue;
|
||||
Color get smallTextColor => brightness == Brightness.light
|
||||
? const Color(0xFF6A6A6A)
|
||||
: const Color(0xFF6A6A6A);
|
||||
Color get darkGreen => brightness == Brightness.light
|
||||
? const Color(0xFF1D713E)
|
||||
: const Color(0xFF07E55E);
|
||||
|
||||
Color get lightGreen => brightness == Brightness.light
|
||||
? const Color(0xFFEDF8F1)
|
||||
: Colors.greenAccent;
|
||||
|
||||
Color get yellow =>
|
||||
brightness == Brightness.light ? const Color(0xFFE9A706) : Colors.yellow;
|
||||
}
|
||||
49
lib/utils/extensions/uicontext.dart
Normal file
49
lib/utils/extensions/uicontext.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
// ignore_for_file: file_names
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension CustomUITheme on BuildContext {
|
||||
TextStyle customLight(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w300, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
TextStyle customBold(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w700, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
TextStyle customRegular(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w400, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
TextStyle customMedium(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w500, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
TextStyle customSemiBold(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w600, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
TextStyle customExtraBold(Color color, double fontSize) {
|
||||
return TextStyle(fontWeight: FontWeight.w800, color: color, fontSize: fontSize, fontFamily: 'Nunito');
|
||||
}
|
||||
|
||||
double screenWidth() {
|
||||
return MediaQuery.sizeOf(this).width;
|
||||
}
|
||||
|
||||
double screenHeight() {
|
||||
return MediaQuery.sizeOf(this).height;
|
||||
}
|
||||
|
||||
EdgeInsets get bodyPadding {
|
||||
return const EdgeInsets.only(left: 15, right: 15);
|
||||
}
|
||||
|
||||
EdgeInsets get bodyLeftOnly {
|
||||
return const EdgeInsets.only(left: 15);
|
||||
}
|
||||
|
||||
EdgeInsets get bodyAllPadding {
|
||||
return const EdgeInsets.all(15);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user