model change
parent
9e5c623184
commit
57f619daff
@ -0,0 +1,156 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:car_provider_app/exceptions/api_exception.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/io_client.dart';
|
||||
|
||||
typedef FactoryConstructor<U> = U Function(dynamic);
|
||||
|
||||
class APIError {
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
|
||||
APIError(this.errorCode, this.errorMessage);
|
||||
|
||||
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage};
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return jsonEncode(this);
|
||||
}
|
||||
}
|
||||
|
||||
APIException _throwAPIException(Response response) {
|
||||
switch (response.statusCode) {
|
||||
case 400:
|
||||
APIError? apiError;
|
||||
if (response.body != null && response.body.isNotEmpty) {
|
||||
var jsonError = jsonDecode(response.body);
|
||||
apiError = APIError(jsonError['errorCode'], jsonError['errorMessage']);
|
||||
}
|
||||
return APIException(APIException.BAD_REQUEST, error: apiError);
|
||||
case 401:
|
||||
return APIException(APIException.UNAUTHORIZED);
|
||||
case 403:
|
||||
return APIException(APIException.FORBIDDEN);
|
||||
case 404:
|
||||
return APIException(APIException.NOT_FOUND);
|
||||
case 500:
|
||||
return APIException(APIException.INTERNAL_SERVER_ERROR);
|
||||
case 444:
|
||||
var downloadUrl = response.headers["location"];
|
||||
return APIException(APIException.UPGRADE_REQUIRED, arguments: downloadUrl);
|
||||
default:
|
||||
return APIException(APIException.OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
class ApiClient {
|
||||
static final ApiClient _instance = ApiClient._internal();
|
||||
|
||||
ApiClient._internal();
|
||||
|
||||
factory ApiClient() => _instance;
|
||||
|
||||
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
||||
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
||||
var _headers = {'Accept': 'application/json'};
|
||||
if (headers != null && headers.isNotEmpty) {
|
||||
_headers.addAll(headers);
|
||||
}
|
||||
if (!kReleaseMode) {
|
||||
print("Url:$url");
|
||||
print("body:$jsonObject");
|
||||
}
|
||||
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes);
|
||||
try {
|
||||
var jsonData = jsonDecode(response.body);
|
||||
return factoryConstructor(jsonData);
|
||||
} catch (ex) {
|
||||
print(ex);
|
||||
throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> postJsonForResponse<T>(String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
||||
String? requestBody;
|
||||
if (jsonObject != null) {
|
||||
requestBody = jsonEncode(jsonObject);
|
||||
if (headers == null) {
|
||||
headers = {'Content-Type': 'application/json'};
|
||||
} else {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
|
||||
return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes);
|
||||
}
|
||||
|
||||
Future<Response> _postForResponse(String url, requestBody, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
||||
try {
|
||||
var _headers = <String, String>{};
|
||||
if (token != null) {
|
||||
_headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
|
||||
if (headers != null && headers.isNotEmpty) {
|
||||
_headers.addAll(headers);
|
||||
}
|
||||
|
||||
if (queryParameters != null) {
|
||||
var queryString = new Uri(queryParameters: queryParameters).query;
|
||||
url = url + '?' + queryString;
|
||||
}
|
||||
var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 60));
|
||||
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
return response;
|
||||
} else {
|
||||
throw _throwAPIException(response);
|
||||
}
|
||||
} on SocketException catch (e) {
|
||||
if (retryTimes > 0) {
|
||||
print('will retry after 3 seconds...');
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
|
||||
} else {
|
||||
throw APIException(APIException.OTHER, arguments: e);
|
||||
}
|
||||
} on HttpException catch (e) {
|
||||
if (retryTimes > 0) {
|
||||
print('will retry after 3 seconds...');
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
|
||||
} else {
|
||||
throw APIException(APIException.OTHER, arguments: e);
|
||||
}
|
||||
} on TimeoutException catch (e) {
|
||||
throw APIException(APIException.TIMEOUT, arguments: e);
|
||||
} on ClientException catch (e) {
|
||||
if (retryTimes > 0) {
|
||||
print('will retry after 3 seconds...');
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
|
||||
} else {
|
||||
throw APIException(APIException.OTHER, arguments: e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _certificateCheck(X509Certificate cert, String host, int port) => true;
|
||||
|
||||
Future<T> _withClient<T>(Future<T> Function(Client) fn) async {
|
||||
var httpClient = HttpClient()..badCertificateCallback = _certificateCheck;
|
||||
var client = IOClient(httpClient);
|
||||
try {
|
||||
return await fn(client);
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
|
||||
class LoginApiClient {
|
||||
static final LoginApiClient _instance = LoginApiClient._internal();
|
||||
|
||||
LoginApiClient._internal();
|
||||
|
||||
factory LoginApiClient() => _instance;
|
||||
|
||||
// Future<CheckMobileAppVersionModel> checkMobileAppVersion() async {
|
||||
// String url = "${ApiConsts.utilitiesRest}CheckMobileAppVersion";
|
||||
// Map<String, dynamic> postParams = {};
|
||||
// postParams.addAll(AppState().postParamsJson);
|
||||
// return await ApiClient().postJsonForObject((json) => CheckMobileAppVersionModel.fromJson(json), url, postParams);
|
||||
// }
|
||||
//
|
||||
// Future<MemberLoginListModel?> memberLogin(String username, String password) async {
|
||||
// String url = "${ApiConsts.erpRest}MemberLogin";
|
||||
// Map<String, dynamic> postParams = {"P_APP_VERSION": "CS", "P_LANGUAGE": "US", "P_PASSWORD": password, "P_USER_NAME": username};
|
||||
// postParams.addAll(AppState().postParamsJson);
|
||||
// return await ApiClient().postJsonForObject((json) {
|
||||
// GenericResponseModel responseData = GenericResponseModel.fromJson(json);
|
||||
// AppState().postParamsObject?.setLogInTokenID = responseData.logInTokenID;
|
||||
// return responseData.memberLoginList;
|
||||
// }, url, postParams);
|
||||
// }
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
|
||||
class TangheemUserApiClient {
|
||||
static final TangheemUserApiClient _instance = TangheemUserApiClient._internal();
|
||||
|
||||
TangheemUserApiClient._internal();
|
||||
|
||||
factory TangheemUserApiClient() => _instance;
|
||||
|
||||
// Future<SurahModel> getSurahs() async {
|
||||
// String url = "${ApiConsts.tangheemUsers}AlSuar_Get";
|
||||
// var postParams = {};
|
||||
// return await ApiClient().postJsonForObject((json) => SurahModel.fromJson(json), url, postParams);
|
||||
// }
|
||||
//
|
||||
// Future<MemberModel> getMembers() async {
|
||||
// String url = "${ApiConsts.tangheemUsers}Committee_Get";
|
||||
// var postParams = {};
|
||||
// return await ApiClient().postJsonForObject((json) => MemberModel.fromJson(json), url, postParams);
|
||||
// }
|
||||
//
|
||||
// Future<ContentInfoModel> getContentInfo(int contentId) async {
|
||||
// String url = "${ApiConsts.tangheemUsers}ContentInfo_Get";
|
||||
// var postParams = {"contentTypeId": contentId};
|
||||
// return await ApiClient().postJsonForObject((json) => ContentInfoModel.fromJson(json), url, postParams);
|
||||
// }
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
//class which loads components "in the background", i.e. ui does not depend on it
|
||||
|
||||
import 'package:car_provider_app/services/shared_preferences.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
//import 'package:revocheckapp/services/firebase_service.dart';
|
||||
|
||||
|
||||
class BackgroundLoader {
|
||||
Future loadBackgroundData() async {
|
||||
//init notification setting
|
||||
try {
|
||||
/*
|
||||
final isPromotionNotificationEnabled = await Injector.appInstance
|
||||
.getDependency<ISharedPreferences>()
|
||||
.promotionNotificationsEnabled;
|
||||
if (isPromotionNotificationEnabled == null) {
|
||||
await Injector.appInstance
|
||||
.getDependency<ISharedPreferences>()
|
||||
.setPromotionNotificationEnabled(true);
|
||||
Injector.appInstance
|
||||
.getDependency<IFirebaseService>()
|
||||
.subscribeForPromotions();
|
||||
} */
|
||||
} catch (_) {
|
||||
//something wend wrong, set it to true
|
||||
await Injector.appInstance
|
||||
.getDependency<ISharedPreferences>()
|
||||
.setPromotionNotificationEnabled(true);
|
||||
/*Injector.appInstance
|
||||
.getDependency<IFirebaseService>()
|
||||
.subscribeForPromotions();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
// import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:car_provider_app/repo/account_repository.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
|
||||
import 'background_loader.dart';
|
||||
|
||||
|
||||
class AppDependencies {
|
||||
static void addDependencies() {
|
||||
Injector injector = Injector.appInstance;
|
||||
|
||||
//add dependencies as needed
|
||||
injector.registerSingleton<IAcRepository>(() => AcRepository());
|
||||
|
||||
// injector.registerSingleton<IAcRepository>((injector) => AcRepository());
|
||||
|
||||
_addCrashlytics();
|
||||
_loadBackgroundTasksNonBlocking();
|
||||
}
|
||||
|
||||
static void _addCrashlytics() {
|
||||
// Set `enableInDevMode` to true to see reports while in debug mode
|
||||
// This is only to be used for confirming that reports are being
|
||||
// submitted as expected. It is not intended to be used for everyday
|
||||
// development.
|
||||
//Crashlytics.instance.enableInDevMode = true;
|
||||
|
||||
// Pass all uncaught errors from the framework to Crashlytics.
|
||||
// FlutterError.onError = Crashlytics.instance.recordFlutterError;
|
||||
}
|
||||
|
||||
static void _loadBackgroundTasksNonBlocking() {
|
||||
final backgroundLoader = BackgroundLoader();
|
||||
backgroundLoader.loadBackgroundData();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:car_provider_app/api/api_client.dart';
|
||||
|
||||
class APIException implements Exception {
|
||||
static const String BAD_REQUEST = 'api_common_bad_request';
|
||||
static const String UNAUTHORIZED = 'api_common_unauthorized';
|
||||
static const String FORBIDDEN = 'api_common_forbidden';
|
||||
static const String NOT_FOUND = 'api_common_not_found';
|
||||
static const String INTERNAL_SERVER_ERROR = 'api_common_internal_server_error';
|
||||
static const String UPGRADE_REQUIRED = 'api_common_upgrade_required';
|
||||
static const String BAD_RESPONSE_FORMAT = 'api_common_bad_response_format';
|
||||
static const String OTHER = 'api_common_http_error';
|
||||
static const String TIMEOUT = 'api_common_http_timeout';
|
||||
static const String UNKNOWN = 'unexpected_error';
|
||||
|
||||
final String message;
|
||||
final APIError? error;
|
||||
final arguments;
|
||||
|
||||
const APIException(this.message, {this.arguments, this.error});
|
||||
|
||||
Map<String, dynamic> toJson() => {'message': message, 'error': error, 'arguments': '$arguments'};
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return jsonEncode(this);
|
||||
}
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:car_provider_app/models/account.dart';
|
||||
import 'package:car_provider_app/models/response_models.dart';
|
||||
import 'package:car_provider_app/services/backend_service.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
|
||||
abstract class IAcRepository {
|
||||
Future<Account> getAccountList();
|
||||
|
||||
Future<BackendResponse> updateAccount(String dataAsJson);
|
||||
}
|
||||
|
||||
class AcRepository implements IAcRepository {
|
||||
static const String ACCOUNT_API_CONTROLLER_MOBILE =
|
||||
"AccountApiControllerMobile/";
|
||||
|
||||
static const String ACCOUNT_LIST = ACCOUNT_API_CONTROLLER_MOBILE + "list";
|
||||
static const String UPDATE_LIST =
|
||||
ACCOUNT_API_CONTROLLER_MOBILE + "saveaccountselected";
|
||||
|
||||
@override
|
||||
Future<Account> getAccountList() async {
|
||||
BackendResponse response = await Injector.appInstance
|
||||
.getDependency<IBackendApiService>()
|
||||
.getAuthenticatedAPI(ACCOUNT_LIST);
|
||||
|
||||
if (response != null && response.isOk) {
|
||||
return Account.fromJson(response.result);
|
||||
} else {
|
||||
throw Exception();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<BackendResponse> updateAccount(String dataAsJson) async {
|
||||
BackendResponse response = await Injector.appInstance
|
||||
.getDependency<IBackendApiService>()
|
||||
.postAuthenticatedAPI(UPDATE_LIST, dataAsJson);
|
||||
|
||||
if (response != null && response.isOk) {
|
||||
//if parsing failed, throw exception
|
||||
return response;
|
||||
} else {
|
||||
throw Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
extension IntExtensions on int {
|
||||
Widget get height => SizedBox(height: toDouble());
|
||||
|
||||
Widget get width => SizedBox(width: toDouble());
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
import 'package:car_provider_app/theme/colors.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
extension EmailValidator on String {
|
||||
Widget get toWidget => Text(this);
|
||||
|
||||
Widget toText10({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(fontSize: 10, fontWeight: isBold ? FontWeight.bold : FontWeight.w600, color: color ?? headingColor, letterSpacing: -0.4),
|
||||
);
|
||||
|
||||
Widget toText11({Color? color, bool isUnderLine = false, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
|
||||
color: color ?? headingColor,
|
||||
letterSpacing: -0.33,
|
||||
decoration: isUnderLine ? TextDecoration.underline : null),
|
||||
);
|
||||
|
||||
Widget toText12({Color? color, bool isUnderLine = false, bool isBold = false, bool isCenter = false, int maxLine = 0}) => Text(
|
||||
this,
|
||||
textAlign: isCenter ? TextAlign.center : null,
|
||||
maxLines: (maxLine > 0) ? maxLine : null,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
|
||||
color: color ?? headingColor,
|
||||
letterSpacing: -0.72,
|
||||
decoration: isUnderLine ? TextDecoration.underline : null),
|
||||
);
|
||||
|
||||
Widget toText13({Color? color, bool isUnderLine = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: color ?? headingColor, letterSpacing: -0.52, decoration: isUnderLine ? TextDecoration.underline : null),
|
||||
);
|
||||
|
||||
Widget toText14({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(color: color ?? headingColor, fontSize: 14, letterSpacing: -0.48, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget toText16({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(color: color ?? headingColor, fontSize: 16, letterSpacing: -0.64, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget toText17({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(color: color ?? headingColor, fontSize: 17, letterSpacing: -0.68, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget toText22({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(height: 1, color: color ?? headingColor, fontSize: 22, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget toText24({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(height: 23 / 24, color: color ?? headingColor, fontSize: 24, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget toText32({Color? color, bool isBold = false}) => Text(
|
||||
this,
|
||||
style: TextStyle(height: 32 / 32, color: color ?? headingColor, fontSize: 32, letterSpacing: -1.92, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
||||
);
|
||||
|
||||
bool isValidEmail() {
|
||||
return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(this);
|
||||
}
|
||||
|
||||
String toFormattedDate() {
|
||||
String date = this.split("T")[0];
|
||||
String time = this.split("T")[1];
|
||||
var dates = date.split("-");
|
||||
return "${dates[2]} ${getMonth(int.parse(dates[1]))} ${dates[0]} ${DateFormat('hh:mm a').format(DateFormat('hh:mm:ss').parse(time))}";
|
||||
}
|
||||
|
||||
getMonth(int month) {
|
||||
switch (month) {
|
||||
case 1:
|
||||
return "January";
|
||||
case 2:
|
||||
return "February";
|
||||
case 3:
|
||||
return "March";
|
||||
case 4:
|
||||
return "April";
|
||||
case 5:
|
||||
return "May";
|
||||
case 6:
|
||||
return "June";
|
||||
case 7:
|
||||
return "July";
|
||||
case 8:
|
||||
return "August";
|
||||
case 9:
|
||||
return "September";
|
||||
case 10:
|
||||
return "October";
|
||||
case 11:
|
||||
return "November";
|
||||
case 12:
|
||||
return "December";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension WidgetExtensions on Widget {
|
||||
Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this);
|
||||
|
||||
Widget paddingAll(double _value) => Padding(padding: EdgeInsets.all(_value), child: this);
|
||||
|
||||
Widget paddingOnly({double left = 0.0, double right = 0.0, double top = 0.0, double bottom = 0.0}) =>
|
||||
Padding(padding: EdgeInsets.only(left: left, right: right, top: top, bottom: bottom), child: this);
|
||||
}
|
||||
@ -1,170 +0,0 @@
|
||||
// import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:car_provider_app/theme/colors.dart';
|
||||
import 'package:car_provider_app/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sizer/sizer.dart';
|
||||
|
||||
enum TxtType {
|
||||
small,
|
||||
normal,
|
||||
heading1,
|
||||
heading2,
|
||||
heading3,
|
||||
appBar,
|
||||
}
|
||||
|
||||
class Txt extends StatelessWidget {
|
||||
String text;
|
||||
int? maxLines;
|
||||
double? fontSize;
|
||||
Color? color;
|
||||
bool? bold;
|
||||
bool? isUnderline;
|
||||
bool? isFlatButton;
|
||||
double? pedding;
|
||||
TextAlign? textAlign;
|
||||
FontWeight? fontWeight;
|
||||
Function? onTap;
|
||||
TxtType txtType;
|
||||
|
||||
Txt(this.text, {this.maxLines, this.color, this.bold, this.fontSize, this.isUnderline, this.isFlatButton, this.pedding, this.textAlign, this.fontWeight, this.onTap, this.txtType = TxtType.normal});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (isFlatButton != null)
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: pedding ?? 0, left: pedding ?? 0),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
onTap!();
|
||||
},
|
||||
customBorder: inkWellCorner(r: 4),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 14,
|
||||
right: 14,
|
||||
top: 6,
|
||||
bottom: 6,
|
||||
),
|
||||
child: getText(),
|
||||
),
|
||||
),
|
||||
);
|
||||
else
|
||||
return getText();
|
||||
}
|
||||
|
||||
Widget getText() {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Text(
|
||||
text,
|
||||
maxLines: maxLines,
|
||||
textAlign: textAlign,
|
||||
overflow: maxLines != null ? TextOverflow.ellipsis : null,
|
||||
style: TextStyle(
|
||||
fontSize: fontSize ??
|
||||
(txtType == TxtType.small
|
||||
? 8.sp
|
||||
: txtType == TxtType.normal
|
||||
? 10.sp
|
||||
: txtType == TxtType.heading1
|
||||
? 11.sp
|
||||
: txtType == TxtType.heading2
|
||||
? 12.sp
|
||||
: txtType == TxtType.heading3
|
||||
? 13.sp
|
||||
: txtType == TxtType.appBar
|
||||
? 14.sp
|
||||
: 8.sp),
|
||||
color: color ??
|
||||
(txtType == TxtType.appBar
|
||||
? Colors.black
|
||||
: txtType == TxtType.heading1
|
||||
? headingColor
|
||||
: txtType == TxtType.heading2
|
||||
? headingColor
|
||||
: txtType == TxtType.heading3
|
||||
? headingColor
|
||||
: null),
|
||||
fontWeight: (fontWeight != null)
|
||||
? fontWeight
|
||||
: ((bold != null)
|
||||
? FontWeight.bold
|
||||
: (txtType == TxtType.appBar
|
||||
? FontWeight.bold
|
||||
: txtType == TxtType.heading1
|
||||
? FontWeight.bold
|
||||
: txtType == TxtType.heading2
|
||||
? FontWeight.bold
|
||||
: txtType == TxtType.heading3
|
||||
? FontWeight.bold
|
||||
: null)),
|
||||
decoration: (isUnderline != null) ? TextDecoration.underline : null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// class TxtAuto extends StatelessWidget {
|
||||
// String text;
|
||||
// int? maxLines;
|
||||
// double? fontSize;
|
||||
// Color? color;
|
||||
// bool? bold;
|
||||
// bool? isUnderline;
|
||||
// bool? isFlatButton;
|
||||
// double? pedding;
|
||||
// TextAlign? textAlign;
|
||||
//
|
||||
// TxtAuto(
|
||||
// this.text, {
|
||||
// this.maxLines,
|
||||
// this.color,
|
||||
// this.bold,
|
||||
// this.fontSize,
|
||||
// this.isUnderline,
|
||||
// this.isFlatButton,
|
||||
// this.pedding,
|
||||
// this.textAlign,
|
||||
// });
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// if (isFlatButton != null)
|
||||
// return Padding(
|
||||
// padding: EdgeInsets.only(right: pedding ?? 0, left: pedding ?? 0),
|
||||
// child: InkWell(
|
||||
// onTap: () {},
|
||||
// customBorder: inkWellCorner(r: 4),
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 14,
|
||||
// right: 14,
|
||||
// top: 6,
|
||||
// bottom: 6,
|
||||
// ),
|
||||
// child: getText(),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// else
|
||||
// return getText();
|
||||
// }
|
||||
//
|
||||
// Widget getText() {
|
||||
// return AutoSizeText(
|
||||
// text,
|
||||
// maxLines: maxLines,
|
||||
// textAlign: textAlign,
|
||||
// overflow: maxLines != null ? TextOverflow.ellipsis : null,
|
||||
// style: TextStyle(
|
||||
// fontSize: fontSize,
|
||||
// color: color,
|
||||
// fontWeight: (bold != null) ? FontWeight.bold : null,
|
||||
// decoration: (isUnderline != null) ? TextDecoration.underline : null,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
Loading…
Reference in New Issue