Enhancements on comments bottom sheet

main_design2.0
zaid_daoud 2 years ago
parent 5b9a33c519
commit c2eb7b0dad

@ -37,96 +37,106 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final commentsProvider = Provider.of<CommentsProvider>(context, listen: false); final commentsProvider = Provider.of<CommentsProvider>(context);
final userProvider = Provider.of<UserProvider>(context, listen: false); final userProvider = Provider.of<UserProvider>(context, listen: false);
return Container( return SingleChildScrollView(
height: MediaQuery.of(context).size.height * 0.55, child: Wrap(
clipBehavior: Clip.antiAlias, children: [
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), Container(
decoration: BoxDecoration( clipBehavior: Clip.antiAlias,
color: Theme.of(context).scaffoldBackgroundColor, margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)), decoration: BoxDecoration(
), color: Theme.of(context).scaffoldBackgroundColor,
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
child: Form( ),
key: _formKey, padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
child: Column( child: Form(
children: [ key: _formKey,
LoadingManager(
isLoading: commentsProvider.isLoading,
isFailedLoading: commentsProvider.comments == null,
stateCode: commentsProvider.stateCode,
onRefresh: () async {
commentsProvider.reset();
await commentsProvider.getComments(callId: widget.requestId);
},
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Container( LoadingManager(
width: 40.toScreenWidth, isLoading: commentsProvider.isLoading,
height: 5.toScreenHeight, isFailedLoading: commentsProvider.comments == null,
decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)), 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, 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,
],
),
), ),
); );
} }

@ -37,17 +37,24 @@ class ServiceRequestDetailsPage extends StatefulWidget {
} }
class _ServiceRequestDetailsPageState extends State<ServiceRequestDetailsPage> { class _ServiceRequestDetailsPageState extends State<ServiceRequestDetailsPage> {
bool loading = false;
ServiceRequest serviceRequest;
@override @override
void didChangeDependencies() { void initState() {
Provider.of<CommentsProvider>(context, listen: false).reset(); super.initState();
super.didChangeDependencies(); loading = true;
setState(() {});
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) async {
Provider.of<CommentsProvider>(context, listen: false).reset();
serviceRequest = await Provider.of<ServiceRequestsProvider>(context, listen: false).getServiceRequestObjectById(requestId: widget.serviceRequest.id);
loading = false;
setState(() {});
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
UserProvider _userProvider = Provider.of<UserProvider>(context); UserProvider _userProvider = Provider.of<UserProvider>(context, listen: false);
ServiceRequestsProvider _serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
// _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id);
Widget informationCard(ServiceRequest serviceRequest) { Widget informationCard(ServiceRequest serviceRequest) {
return Column( return Column(
@ -210,14 +217,9 @@ class _ServiceRequestDetailsPageState extends State<ServiceRequestDetailsPage> {
appBar: DefaultAppBar(title: context.translation.serviceDetails), appBar: DefaultAppBar(title: context.translation.serviceDetails),
//backgroundColor: const Color(0xfff8f9fb), //backgroundColor: const Color(0xfff8f9fb),
body: SafeArea( body: SafeArea(
child: FutureBuilder( child: loading
future: _serviceRequestsProvider.getServiceRequestObjectById(requestId: widget.serviceRequest.id), ? const ALoading().center
builder: (context, snap) { : Column(
if (snap.connectionState == ConnectionState.waiting) {
return const ALoading();
} else if (snap.hasData) {
ServiceRequest serviceRequest = snap.data;
return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SingleChildScrollView( SingleChildScrollView(
@ -255,11 +257,7 @@ class _ServiceRequestDetailsPageState extends State<ServiceRequestDetailsPage> {
)) ))
.paddingOnly(start: 16, end: 16, bottom: 24), .paddingOnly(start: 16, end: 16, bottom: 24),
], ],
); ),
}
return const SizedBox();
},
),
), ),
); );
} }

Loading…
Cancel
Save