diff --git a/lib/views/pages/user/requests/comments_bottom_sheet.dart b/lib/views/pages/user/requests/comments_bottom_sheet.dart index a178ec0f..38d6a899 100644 --- a/lib/views/pages/user/requests/comments_bottom_sheet.dart +++ b/lib/views/pages/user/requests/comments_bottom_sheet.dart @@ -37,96 +37,106 @@ class _CommentsBottomSheetState extends State { @override Widget build(BuildContext context) { - final commentsProvider = Provider.of(context, listen: false); + final commentsProvider = Provider.of(context); final userProvider = Provider.of(context, listen: false); - return Container( - height: MediaQuery.of(context).size.height * 0.55, - clipBehavior: Clip.antiAlias, - margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - decoration: BoxDecoration( - color: Theme.of(context).scaffoldBackgroundColor, - borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), - ), - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - child: Form( - key: _formKey, - child: Column( - children: [ - LoadingManager( - isLoading: commentsProvider.isLoading, - isFailedLoading: commentsProvider.comments == null, - stateCode: commentsProvider.stateCode, - onRefresh: () async { - commentsProvider.reset(); - await commentsProvider.getComments(callId: widget.requestId); - }, + return SingleChildScrollView( + child: Wrap( + children: [ + Container( + clipBehavior: Clip.antiAlias, + margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + decoration: BoxDecoration( + color: Theme.of(context).scaffoldBackgroundColor, + borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), + ), + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), + child: Form( + key: _formKey, child: Column( - crossAxisAlignment: CrossAxisAlignment.center, children: [ - Container( - width: 40.toScreenWidth, - height: 5.toScreenHeight, - decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), + LoadingManager( + isLoading: commentsProvider.isLoading, + isFailedLoading: commentsProvider.comments == null, + stateCode: commentsProvider.stateCode, + onRefresh: () async { + commentsProvider.reset(); + await commentsProvider.getComments(callId: widget.requestId); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + width: 40.toScreenWidth, + height: 5.toScreenHeight, + decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), + ), + 16.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600), + ), + commentsProvider.comments.isEmpty + ? SizedBox( + height: MediaQuery.of(context).size.height * 0.25, + child: NoItemFound(message: context.translation.noDataFound), + ) + : LazyLoading( + nextPage: commentsProvider.nextPage, + onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId), + child: ListView.separated( + itemCount: commentsProvider.comments.length, + padding: const EdgeInsets.only(top: 16, bottom: 8), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + separatorBuilder: (cxt, index) => 8.height, + itemBuilder: (context, itemIndex) { + final model = commentsProvider.comments[itemIndex]; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (model?.createdBy?.userName ?? "Nurse").heading6(context), + 8.height, + (model?.comment ?? "").bodyText(context), + 8.height, + Align( + alignment: AlignmentDirectional.bottomEnd, + child: Text(DateTime.tryParse(model.createdOn).toIso8601String().toServiceRequestDetailsFormat, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)), + ), + ], + ).toShadowContainer(context); + }, + ), + ), + ], + ), ), + if (userProvider.user.type == UsersTypes.normal_user) 8.height, + if (userProvider.user.type == UsersTypes.normal_user) // todo its keeps loading when open keyboard or dismiss + AppTextFormField( + labelText: "Type any comment", + backgroundColor: AppColor.neutral30, + alignLabelWithHint: true, + showShadow: false, + validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredField, + textInputType: TextInputType.multiline, + suffixIcon: "comment_send".toSvgAsset().paddingOnly(end: 16).onPress(() { + if (_formKey.currentState.validate()) { + _formKey.currentState.save(); + final comment = Comment(id: 0, callRequestId: num.tryParse(widget.requestId ?? ""), comment: text); + commentsProvider.addComment(context, comment: comment); + } + }), + onSaved: (value) { + text = value; + }, + ), 16.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.comments.heading3(context).custom(fontWeight: FontWeight.w600), - ), - commentsProvider.comments.isEmpty - ? NoItemFound(message: context.translation.noDataFound).expanded - : LazyLoading( - nextPage: commentsProvider.nextPage, - onLazyLoad: () async => await commentsProvider.getComments(callId: widget.requestId), - child: ListView.separated( - itemCount: commentsProvider.comments.length, - padding: const EdgeInsets.only(top: 16, bottom: 8), - separatorBuilder: (cxt, index) => 8.height, - itemBuilder: (context, itemIndex) { - final model = commentsProvider.comments[itemIndex]; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - (model?.createdBy?.userName ?? "Nurse").heading6(context), - 8.height, - (model?.comment ?? "").bodyText(context), - 8.height, - Align( - alignment: AlignmentDirectional.bottomEnd, - child: Text(DateTime.tryParse(model.createdOn).toIso8601String().toServiceRequestDetailsFormat, - style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50)), - ), - ], - ).toShadowContainer(context); - }, - ), - ).expanded, ], ), - ).expanded, - if (userProvider.user.type == UsersTypes.normal_user) 8.height, - if (userProvider.user.type == UsersTypes.normal_user) // todo its keeps loading when open keyboard or dismiss - AppTextFormField( - labelText: "Type any comment", - backgroundColor: AppColor.neutral30, - alignLabelWithHint: true, - showShadow: false, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredField, - textInputType: TextInputType.multiline, - suffixIcon: "comment_send".toSvgAsset().paddingOnly(end: 16).onPress(() { - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); - final comment = Comment(id: 0, callRequestId: num.tryParse(widget.requestId ?? ""), comment: text); - commentsProvider.addComment(context, comment: comment); - } - }), - onSaved: (value) { - text = value; - }, - ), - 16.height, - ], - ), + ), + ), + ], ), ); } diff --git a/lib/views/pages/user/requests/service_request_details.dart b/lib/views/pages/user/requests/service_request_details.dart index b0e67463..f0157eaa 100644 --- a/lib/views/pages/user/requests/service_request_details.dart +++ b/lib/views/pages/user/requests/service_request_details.dart @@ -37,17 +37,24 @@ class ServiceRequestDetailsPage extends StatefulWidget { } class _ServiceRequestDetailsPageState extends State { + bool loading = false; + ServiceRequest serviceRequest; @override - void didChangeDependencies() { - Provider.of(context, listen: false).reset(); - super.didChangeDependencies(); + void initState() { + super.initState(); + loading = true; + setState(() {}); + WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) async { + Provider.of(context, listen: false).reset(); + serviceRequest = await Provider.of(context, listen: false).getServiceRequestObjectById(requestId: widget.serviceRequest.id); + loading = false; + setState(() {}); + }); } @override Widget build(BuildContext context) { - UserProvider _userProvider = Provider.of(context); - ServiceRequestsProvider _serviceRequestsProvider = Provider.of(context); - // _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id); + UserProvider _userProvider = Provider.of(context, listen: false); Widget informationCard(ServiceRequest serviceRequest) { return Column( @@ -210,14 +217,9 @@ class _ServiceRequestDetailsPageState extends State { appBar: DefaultAppBar(title: context.translation.serviceDetails), //backgroundColor: const Color(0xfff8f9fb), body: SafeArea( - child: FutureBuilder( - future: _serviceRequestsProvider.getServiceRequestObjectById(requestId: widget.serviceRequest.id), - builder: (context, snap) { - if (snap.connectionState == ConnectionState.waiting) { - return const ALoading(); - } else if (snap.hasData) { - ServiceRequest serviceRequest = snap.data; - return Column( + child: loading + ? const ALoading().center + : Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SingleChildScrollView( @@ -255,11 +257,7 @@ class _ServiceRequestDetailsPageState extends State { )) .paddingOnly(start: 16, end: 16, bottom: 24), ], - ); - } - return const SizedBox(); - }, - ), + ), ), ); }