Merge branch 'master' of http://34.17.182.140/Haroon6138/HMG_Patient_App_New into dev_sultan
* 'master' of http://34.17.182.140/Haroon6138/HMG_Patient_App_New: Implemented CloudFlare TurnStile Update to stores VersionID 21.6 updates update Updates hardcoded admin removed LAB RESULT CHANGES ADDED LAB RESULT CHANGES ADDED updates for dental & laser clinics Fixes for Apple Watch integration updates Update to stores VersionID 21.4pull/344/head^2
commit
0536d8b978
@ -0,0 +1,56 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
||||||
|
|
||||||
|
/// Service to handle Cloudflare Turnstile captcha verification
|
||||||
|
class TurnstileService {
|
||||||
|
final LoggerService _loggerService;
|
||||||
|
|
||||||
|
// Replace with your Cloudflare Turnstile site key
|
||||||
|
static const String _siteKey = '0x4AAAAAAAkmbvEy63pcxBBt';
|
||||||
|
|
||||||
|
TurnstileService(this._loggerService);
|
||||||
|
|
||||||
|
/// Get Turnstile token using invisible mode
|
||||||
|
/// Returns the token on success, null on failure
|
||||||
|
Future<String?> getTurnstileToken() async {
|
||||||
|
// Initialize an instance of invisible Cloudflare Turnstile with your site key
|
||||||
|
final turnstile = CloudflareTurnstile.invisible(
|
||||||
|
siteKey: _siteKey,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get the Turnstile token
|
||||||
|
final token = await turnstile.getToken();
|
||||||
|
_loggerService.logInfo('Turnstile token retrieved successfully');
|
||||||
|
return token; // Return the token upon success
|
||||||
|
} on TurnstileException catch (e) {
|
||||||
|
// Handle Turnstile failure
|
||||||
|
_loggerService.logError('Turnstile challenge failed: ${e.message}');
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Challenge failed: ${e.message}');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Handle any other exceptions
|
||||||
|
_loggerService.logError('Unexpected error during Turnstile challenge: $e');
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Unexpected error: $e');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Ensure the Turnstile instance is properly disposed of
|
||||||
|
turnstile.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return null if the token couldn't be generated
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the site key for Turnstile widget
|
||||||
|
String getSiteKey() => _siteKey;
|
||||||
|
|
||||||
|
/// Validate if Turnstile is properly configured
|
||||||
|
bool isConfigured() {
|
||||||
|
return _siteKey.isNotEmpty && _siteKey != '0x4AAAAAAAkmbvEy63pcxBBt';
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@ -1,45 +1,275 @@
|
|||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
||||||
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
||||||
|
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
|
||||||
import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
|
import 'package:hmg_patient_app_new/features/lab/lab_view_model.dart';
|
||||||
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart';
|
import 'package:hmg_patient_app_new/features/lab/models/resp_models/lab_result.dart';
|
||||||
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
|
||||||
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart';
|
import 'package:hmg_patient_app_new/presentation/lab/lab_result_via_clinic/lab_order_result_item.dart';
|
||||||
import 'package:provider/provider.dart' show Selector, Provider, ReadContext;
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
||||||
|
import 'package:hmg_patient_app_new/widgets/date_range_selector/viewmodel/date_range_view_model.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../../../core/dependencies.dart' show getIt;
|
||||||
|
import '../../../core/utils/size_utils.dart' show ResponsiveExtension;
|
||||||
|
import '../../../generated/locale_keys.g.dart' show LocaleKeys;
|
||||||
|
|
||||||
import '../../../widgets/date_range_selector/viewmodel/date_range_view_model.dart';
|
class LabResultList extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
State<LabResultList> createState() => _LabResultListState();
|
||||||
|
}
|
||||||
|
|
||||||
class LabResultList extends StatelessWidget {
|
class _LabResultListState extends State<LabResultList> {
|
||||||
late LabViewModel model;
|
late LabViewModel model;
|
||||||
|
int expandedIndex = -1;
|
||||||
|
Map<int, bool> descriptionExpandedMap = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
model = Provider.of<LabViewModel>(context);
|
model = Provider.of<LabViewModel>(context);
|
||||||
return Selector<LabViewModel, List<LabResult>>(
|
return Selector<LabViewModel, Map<String, List<LabResult>>>(
|
||||||
selector: (_, model) => model.mainLabResultsByHospitals,
|
selector: (_, model) => model.mainLabResultsByPackageName,
|
||||||
builder: (__, list, ___) {
|
builder: (__, groupedResults, ___) {
|
||||||
if (list.isEmpty && context.read<LabViewModel>().labSpecialResult.isEmpty) {
|
if (groupedResults.isEmpty && context.read<LabViewModel>().labSpecialResult.isEmpty) {
|
||||||
// return Utils.getNoDataWidget(context,
|
// return Utils.getNoDataWidget(context,
|
||||||
// noDataText: LocaleKeys.noLabResults.tr(context: context));
|
// noDataText: LocaleKeys.noLabResults.tr(context: context));
|
||||||
return Container();
|
return Container();
|
||||||
} else {
|
} else {
|
||||||
|
// Convert map entries to a list for indexed access
|
||||||
|
final packageEntries = groupedResults.entries.toList();
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
physics: NeverScrollableScrollPhysics(),
|
physics: NeverScrollableScrollPhysics(),
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
shrinkWrap: true,itemCount: list.length,itemBuilder: (____, index) {
|
shrinkWrap: true,
|
||||||
var labItem = list[index];
|
itemCount: packageEntries.length,
|
||||||
return LabOrderResultItem(onTap: () {
|
itemBuilder: (context, packageIndex) {
|
||||||
context.read<DateRangeSelectorRangeViewModel>().flush();
|
final packageName = packageEntries[packageIndex].key;
|
||||||
model.getPatientLabResult(model.currentlySelectedPatientOrder!, labItem.description ?? "", labItem.testShortDescription ?? "", labItem.uOM ?? "");
|
final labResults = packageEntries[packageIndex].value;
|
||||||
},
|
final isExpanded = expandedIndex == packageIndex;
|
||||||
tests: labItem,
|
|
||||||
index: index,
|
return AnimatedContainer(
|
||||||
iconColor: model.getColor(labItem.calculatedResultFlag ?? "N"),
|
duration: Duration(milliseconds: 300),
|
||||||
severityText: model.getSeverityText(labItem.calculatedResultFlag ?? "N"));
|
curve: Curves.easeInOut,
|
||||||
});
|
margin: EdgeInsets.symmetric(vertical: 8.h),
|
||||||
|
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r, hasShadow: true),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// Package name as title/header
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.0.h),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
spacing: 8.h,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: packageName.toText18(
|
||||||
|
isBold: true
|
||||||
|
),
|
||||||
|
),
|
||||||
|
AnimatedRotation(
|
||||||
|
turns: isExpanded ? 0.5 : 0,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
child: Icon(Icons.expand_more),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if(labResults.first.packageShortDescription != null)
|
||||||
|
_ExpandableDescriptionText(
|
||||||
|
description: labResults.first.packageShortDescription!,
|
||||||
|
isExpanded: descriptionExpandedMap[packageIndex] ?? false,
|
||||||
|
onToggle: () {
|
||||||
|
setState(() {
|
||||||
|
descriptionExpandedMap[packageIndex] = !(descriptionExpandedMap[packageIndex] ?? false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else
|
||||||
|
SizedBox.shrink()
|
||||||
|
],
|
||||||
|
),),
|
||||||
|
|
||||||
|
// Lab results under this package with animation
|
||||||
|
AnimatedSize(
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
child: isExpanded
|
||||||
|
? Column(
|
||||||
|
children: labResults.asMap().entries.map((entry) {
|
||||||
|
final index = entry.key;
|
||||||
|
final labItem = entry.value;
|
||||||
|
|
||||||
|
return TweenAnimationBuilder<double>(
|
||||||
|
tween: Tween(begin: 0.0, end: 1.0),
|
||||||
|
duration: Duration(milliseconds: 300 + (index * 50)),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
builder: (context, value, child) {
|
||||||
|
return Opacity(
|
||||||
|
opacity: value,
|
||||||
|
child: Transform.translate(
|
||||||
|
offset: Offset(0, 20 * (1 - value)),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
LabOrderResultItem(
|
||||||
|
onTap: () {
|
||||||
|
context.read<DateRangeSelectorRangeViewModel>().flush();
|
||||||
|
model.getPatientLabResult(
|
||||||
|
model.currentlySelectedPatientOrder!,
|
||||||
|
labItem.description ?? "",
|
||||||
|
labItem.testShortDescription ?? "",
|
||||||
|
labItem.uOM ?? ""
|
||||||
|
);
|
||||||
|
},
|
||||||
|
tests: labItem,
|
||||||
|
index: index,
|
||||||
|
iconColor: model.getColor(labItem.calculatedResultFlag ?? "N"),
|
||||||
|
severityText: model.getSeverityText(labItem.calculatedResultFlag ?? "N")
|
||||||
|
),
|
||||||
|
if(labResults.length>1)
|
||||||
|
...[SizedBox(
|
||||||
|
height: 8.h,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.h),
|
||||||
|
child: Divider(
|
||||||
|
color: AppColors.dividerColor,
|
||||||
|
thickness: 1.h,
|
||||||
|
),
|
||||||
|
)]
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
)
|
||||||
|
: SizedBox.shrink(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
).onPress((){
|
||||||
|
setState(() {
|
||||||
|
expandedIndex = isExpanded ? -1 : packageIndex;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExpandableDescriptionText extends StatelessWidget {
|
||||||
|
final String description;
|
||||||
|
final bool isExpanded;
|
||||||
|
final VoidCallback onToggle;
|
||||||
|
|
||||||
|
const _ExpandableDescriptionText({
|
||||||
|
required this.description,
|
||||||
|
required this.isExpanded,
|
||||||
|
required this.onToggle,
|
||||||
|
});
|
||||||
|
|
||||||
|
static TextStyle get textStyle => TextStyle(
|
||||||
|
fontSize: 14.f,
|
||||||
|
color: AppColors.textColorLight,
|
||||||
|
// or Colors.black87
|
||||||
|
// fontFamily: 'Poppins',
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
fontStyle: FontStyle.normal,
|
||||||
|
height: 1.4,
|
||||||
|
letterSpacing: 0.0,
|
||||||
|
decoration: TextDecoration.none,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final readMoreText = isExpanded
|
||||||
|
? ' ${LocaleKeys.hide.tr()}'
|
||||||
|
: ' ${LocaleKeys.readMore.tr(context: context)}';
|
||||||
|
|
||||||
|
final readMoreStyle = TextStyle(
|
||||||
|
fontSize: 12.f,
|
||||||
|
color: AppColors.primaryRedColor,
|
||||||
|
// fontFamily: 'Poppins',
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
);
|
||||||
|
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
// Check if description alone overflows 2 lines
|
||||||
|
final descriptionPainter = TextPainter(
|
||||||
|
text: TextSpan(text: description, style: textStyle),
|
||||||
|
maxLines: 2,
|
||||||
|
textDirection: Directionality.of(context),
|
||||||
|
)..layout(maxWidth: constraints.maxWidth);
|
||||||
|
|
||||||
|
final isOverflowing = descriptionPainter.didExceedMaxLines;
|
||||||
|
|
||||||
|
// No overflow, or already expanded -> show full text
|
||||||
|
if (!isOverflowing || isExpanded) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: isOverflowing ? onToggle : null,
|
||||||
|
child: Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
style: textStyle,
|
||||||
|
children: [
|
||||||
|
TextSpan(text: description, style: textStyle),
|
||||||
|
if (isOverflowing)
|
||||||
|
TextSpan(text: readMoreText, style: readMoreStyle),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Binary search for max chars that fit in 2 lines with "Read more" appended
|
||||||
|
int low = 0, high = description.length;
|
||||||
|
while (low < high) {
|
||||||
|
final mid = (low + high + 1) ~/ 2;
|
||||||
|
final testPainter = TextPainter(
|
||||||
|
text: TextSpan(
|
||||||
|
style: textStyle,
|
||||||
|
children: [
|
||||||
|
TextSpan(text: '${description.substring(0, mid)}...'),
|
||||||
|
TextSpan(text: readMoreText, style: readMoreStyle),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
textDirection: Directionality.of(context),
|
||||||
|
)..layout(maxWidth: constraints.maxWidth);
|
||||||
|
|
||||||
|
if (testPainter.didExceedMaxLines) {
|
||||||
|
high = mid - 1;
|
||||||
|
} else {
|
||||||
|
low = mid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final truncated = description.substring(0, low).trimRight();
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onToggle,
|
||||||
|
child: Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
style: textStyle,
|
||||||
|
children: [
|
||||||
|
TextSpan(text: '$truncated...'),
|
||||||
|
TextSpan(text: readMoreText, style: readMoreStyle),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue