From 23a6b6d1d9682aef2e41325e575a097b68f027e3 Mon Sep 17 00:00:00 2001 From: jantunesmessias Date: Wed, 19 Feb 2025 09:53:26 -0300 Subject: [PATCH] WIP --- .../details_component_widget.dart | 415 +++++++++--------- lib/features/documents/documents.dart | 76 ++-- lib/shared/mixins/template_mixin.dart | 2 +- lib/shared/widgets/read_view.dart | 20 +- 4 files changed, 262 insertions(+), 251 deletions(-) diff --git a/lib/components/templates_components/details_component/details_component_widget.dart b/lib/components/templates_components/details_component/details_component_widget.dart index 231092f6..9754639d 100644 --- a/lib/components/templates_components/details_component/details_component_widget.dart +++ b/lib/components/templates_components/details_component/details_component_widget.dart @@ -64,218 +64,225 @@ class _DetailsComponentWidgetState extends State { // CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); final double limitedBodyFontSize = LimitedFontSizeUtil.getBodyFontSize(context); - return Container( - constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width, - maxHeight: MediaQuery.of(context).size.height, - ), - decoration: BoxDecoration( - color: FlutterFlowTheme.of(context).primaryBackground, - borderRadius: const BorderRadius.all(Radius.circular(25.0)), - ), - child: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox(height: MediaQuery.of(context).size.height * 0.02), - if (widget.imagePath != null && widget.imagePath != '') - Container( - width: MediaQuery.of(context).size.width * 0.3, - height: MediaQuery.of(context).size.width * 0.3, - clipBehavior: Clip.antiAlias, - decoration: const BoxDecoration( - shape: BoxShape.circle, + return Material( + type: MaterialType.transparency, + child: Container( + constraints: BoxConstraints( + maxWidth: MediaQuery.of(context).size.width, + maxHeight: MediaQuery.of(context).size.height, + ), + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primaryBackground, + borderRadius: const BorderRadius.all(Radius.circular(25.0)), + ), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + SizedBox(height: MediaQuery.of(context).size.height * 0.02), + if (widget.imagePath != null && widget.imagePath != '') + Container( + width: MediaQuery.of(context).size.width * 0.3, + height: MediaQuery.of(context).size.width * 0.3, + clipBehavior: Clip.antiAlias, + decoration: const BoxDecoration( + shape: BoxShape.circle, + ), + child: CachedNetworkImage( + fadeInDuration: const Duration(milliseconds: 100), + fadeOutDuration: const Duration(milliseconds: 100), + imageUrl: widget.imagePath!, + fit: BoxFit.cover, + useOldImageOnUrlChange: true, + ), ), - child: CachedNetworkImage( - fadeInDuration: const Duration(milliseconds: 100), - fadeOutDuration: const Duration(milliseconds: 100), - imageUrl: widget.imagePath!, - fit: BoxFit.cover, - useOldImageOnUrlChange: true, - ), - ), - SizedBox(height: MediaQuery.of(context).size.height * 0.03), - Row( - children: statusLinkedHashMap.expand((linkedHashMap) { - return linkedHashMap.entries - .map((MapEntry item) { - return Expanded( - child: Padding( - padding: EdgeInsets.symmetric( - horizontal: MediaQuery.of(context).size.width * 0.05, - ), - child: TextFormField( - autofocus: false, - canRequestFocus: false, - readOnly: true, - obscureText: false, - decoration: InputDecoration( - isDense: true, - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: item.value, - ), - ), - filled: true, - fillColor: item.value, - labelText: item.key, - labelStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: FlutterFlowTheme.of(context) - .labelMediumFamily, - fontWeight: FontWeight.bold, - color: FlutterFlowTheme.of(context).info, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context) - .labelMediumFamily, - ), - fontSize: limitedBodyFontSize, - ), - hintStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: FlutterFlowTheme.of(context) - .labelMediumFamily, - color: FlutterFlowTheme.of(context).info, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context) - .labelMediumFamily, - ), - fontSize: limitedBodyFontSize, - ), - focusedBorder: InputBorder.none, - errorBorder: InputBorder.none, - focusedErrorBorder: InputBorder.none, - suffixIcon: Icon( - Icons.info, - color: FlutterFlowTheme.of(context).info, - ), + SizedBox(height: MediaQuery.of(context).size.height * 0.03), + Row( + children: statusLinkedHashMap.expand((linkedHashMap) { + return linkedHashMap.entries + .map((MapEntry item) { + return Expanded( + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: MediaQuery.of(context).size.width * 0.05, ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - color: FlutterFlowTheme.of(context).info, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily, + child: TextFormField( + autofocus: false, + canRequestFocus: false, + readOnly: true, + obscureText: false, + decoration: InputDecoration( + isDense: true, + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: item.value, ), - fontSize: limitedBodyFontSize, ), - textAlign: TextAlign.center, - maxLines: null, - keyboardType: TextInputType.name, - validator: _model.textController1Validator - .asValidator(context), + filled: true, + fillColor: item.value, + labelText: item.key, + labelStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: FlutterFlowTheme.of(context) + .labelMediumFamily, + fontWeight: FontWeight.bold, + color: FlutterFlowTheme.of(context).info, + letterSpacing: 0.0, + useGoogleFonts: + GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context) + .labelMediumFamily, + ), + fontSize: limitedBodyFontSize, + ), + hintStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: FlutterFlowTheme.of(context) + .labelMediumFamily, + color: FlutterFlowTheme.of(context).info, + letterSpacing: 0.0, + useGoogleFonts: + GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context) + .labelMediumFamily, + ), + fontSize: limitedBodyFontSize, + ), + focusedBorder: InputBorder.none, + errorBorder: InputBorder.none, + focusedErrorBorder: InputBorder.none, + suffixIcon: Icon( + Icons.info, + color: FlutterFlowTheme.of(context).info, + ), + ), + style: FlutterFlowTheme.of(context) + .bodyMedium + .override( + fontFamily: FlutterFlowTheme.of(context) + .bodyMediumFamily, + color: FlutterFlowTheme.of(context).info, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).bodyMediumFamily, + ), + fontSize: limitedBodyFontSize, + ), + textAlign: TextAlign.center, + maxLines: null, + keyboardType: TextInputType.name, + validator: _model.textController1Validator + .asValidator(context), + ), + ), + ); + }).toList(); + }).toList(), + ), + SizedBox(height: MediaQuery.of(context).size.height * 0.03), + ListView.builder( + shrinkWrap: true, + itemCount: labelsLinkedHashMap.length, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + String key = labelsLinkedHashMap.keys.elementAt(index); + String value = labelsLinkedHashMap[key]!; + // return Text('key: $key, value: $value'); + return TextFormField( + readOnly: true, + initialValue: value, + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: + FlutterFlowTheme.of(context).bodyMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).bodyMediumFamily, + ), + fontSize: limitedBodyFontSize, + ), + decoration: InputDecoration( + labelText: key, + filled: true, + fillColor: FlutterFlowTheme.of(context).primaryBackground, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, // Change border color here + ), + ), + labelStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: + FlutterFlowTheme.of(context).labelMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).labelMediumFamily, + ), + ), + hintStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: + FlutterFlowTheme.of(context).labelMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).labelMediumFamily, + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, // Change border color here + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, // Change border color here + ), + ), + errorBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, // Change border color here + ), + ), + focusedErrorBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, // Change border color here + ), ), ), ); - }).toList(); - }).toList(), - ), - SizedBox(height: MediaQuery.of(context).size.height * 0.03), - ListView.builder( - shrinkWrap: true, - itemCount: labelsLinkedHashMap.length, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - String key = labelsLinkedHashMap.keys.elementAt(index); - String value = labelsLinkedHashMap[key]!; - // return Text('key: $key, value: $value'); - return TextFormField( - readOnly: true, - initialValue: value, - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily, - ), - fontSize: limitedBodyFontSize, - ), - decoration: InputDecoration( - labelText: key, - filled: true, - fillColor: FlutterFlowTheme.of(context).primaryBackground, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, // Change border color here - ), - ), - labelStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: - FlutterFlowTheme.of(context).labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily, - ), - ), - hintStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: - FlutterFlowTheme.of(context).labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily, - ), - ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, // Change border color here - ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, // Change border color here - ), - ), - errorBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, // Change border color here - ), - ), - focusedErrorBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10.0), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, // Change border color here - ), - ), - ), - ); - }, - ), - SizedBox(height: MediaQuery.of(context).size.height * 0.02), - if (widget.buttons!.isNotEmpty || widget.buttons != null) - OverflowBar( - overflowAlignment: OverflowBarAlignment.center, - alignment: MainAxisAlignment.center, - overflowSpacing: 2, - spacing: 2, - // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: widget.buttons!, + }, ), - SizedBox(height: MediaQuery.of(context).size.height * 0.02), - ], + SizedBox(height: MediaQuery.of(context).size.height * 0.02), + if (widget.buttons!.isNotEmpty || widget.buttons != null) + OverflowBar( + overflowAlignment: OverflowBarAlignment.center, + alignment: MainAxisAlignment.center, + overflowSpacing: 2, + spacing: 2, + // mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: widget.buttons!, + ), + SizedBox(height: MediaQuery.of(context).size.height * 0.02), + ], + ), ), ), ); diff --git a/lib/features/documents/documents.dart b/lib/features/documents/documents.dart index 706e17df..59bf9b22 100644 --- a/lib/features/documents/documents.dart +++ b/lib/features/documents/documents.dart @@ -23,6 +23,15 @@ part 'documents.rxb.g.dart'; typedef DocumentKey = GlobalKey; +/// ----------------------------------------------- +/// [Extensions] --------------------------------- +/// ----------------------------------------------- + +extension ExplicitRxdartStartWithExtension on Stream { + Stream rxdartStartWith(T? value) => + rx.StartWithExtension(this).startWith(value); +} + /// ----------------------------------------------- /// [Pages] --------------------------------------- /// ----------------------------------------------- @@ -146,45 +155,56 @@ class DocumentViewerScreen extends StatefulScreen { } class _DocumentViewerScreenState extends ScreenState { + @override + void initState() { + super.initState(); + } + @override Widget build(BuildContext context) { final String title = widget.doc.$1.description; final theme = FlutterFlowTheme.of(context); final locale = FFLocalizations.of(context); + final Color color = widget.doc.$1.category.color; + ; backAction() => widget.bloc.events.unselectDocument(); infoAction() => DetailsComponentWidget( buttons: [], - statusHashMap: [], + statusHashMap: [ + Map.from({ + widget.doc.$1.description: widget.doc.$1.category.color, + }) + ], labelsHashMap: Map.from({ locale.getVariableText( enText: 'Description', ptText: 'Descrição', ): widget.doc.$1.description, - locale.getVariableText( - enText: 'Type', - ptText: 'Tipo', - ): widget.doc.$1.type, locale.getVariableText( enText: 'Category', ptText: 'Categoria', ): widget.doc.$1.category.title, - locale.getVariableText( - enText: 'Person', - ptText: 'Pessoa', - ): widget.doc.$1.person, - locale.getVariableText( - enText: 'Property', - ptText: 'Propriedade', - ): widget.doc.$1.property, + if (widget.doc.$1.person.isNotEmpty) + locale.getVariableText( + enText: 'Person', + ptText: 'Pessoa', + ): widget.doc.$1.person, + if (widget.doc.$1.property.isNotEmpty) + locale.getVariableText( + enText: 'Property', + ptText: 'Propriedade', + ): widget.doc.$1.property, locale.getVariableText( enText: 'Created At', ptText: 'Criado em', - ): widget.doc.$1.createdAt, + ): ValidatorUtil.toLocalDateTime( + 'yyyy-MM-dd', widget.doc.$1.createdAt), locale.getVariableText( enText: 'Updated At', ptText: 'Atualizado em', - ): widget.doc.$1.updatedAt, + ): ValidatorUtil.toLocalDateTime( + 'yyyy-MM-dd', widget.doc.$1.updatedAt), }), ); @@ -200,10 +220,7 @@ class _DocumentViewerScreenState extends ScreenState { } Widget buildBody(BuildContext context) { - // final PDFViewerKey _viewerKey = PDFViewerKey(); - return ReadView( - // search: _viewerKey, title: widget.doc.$1.description, url: widget.doc.$2.toString(), ); @@ -256,7 +273,7 @@ class DocumentModel extends FlutterFlowModel { BuildContext context, T item, int index) { log('ItemBuilder -> $index'); - return DocumentItem( + return DocumentComponent( document: item, onPressed: onView, ); @@ -311,8 +328,8 @@ class DocumentModel extends FlutterFlowModel { /// [Footer] - CategoryItem categoryItemBuilder(T? item) { - return CategoryItem(category: item! as Category); + CategoryComponent categoryItemBuilder(T? item) { + return CategoryComponent(category: item! as Category); } Widget itemFooterBuilder(Future> Function() gen) => @@ -479,11 +496,6 @@ class DocumentModel extends FlutterFlowModel { /// [BLoCs] --------------------------------------- /// ----------------------------------------------- -extension RxdartStartWithExtension on Stream { - Stream rxdartStartWith(T? value) => - rx.StartWithExtension(this).startWith(value); -} - abstract class DocumentPageBlocEvents { void selectDocument(Document document); void unselectDocument(); @@ -589,11 +601,11 @@ interface class Category extends Archive { /// ----------------------------------------------- // ignore: must_be_immutable -class DocumentItem extends StatelessComponent { +class DocumentComponent extends StatelessComponent { final Document document; void Function(Document, BuildContext) onPressed; - DocumentItem({ + DocumentComponent({ super.key, required this.document, required this.onPressed, @@ -721,20 +733,20 @@ class DocumentItem extends StatelessComponent { ); } - DocumentItem copyWith({ + DocumentComponent copyWith({ Document? document, }) { - return DocumentItem( + return DocumentComponent( document: document ?? this.document, onPressed: onPressed, ); } } -class CategoryItem extends StatelessComponent { +class CategoryComponent extends StatelessComponent { final Category category; - const CategoryItem({ + const CategoryComponent({ super.key, required this.category, }); diff --git a/lib/shared/mixins/template_mixin.dart b/lib/shared/mixins/template_mixin.dart index f3184e56..2e3611d0 100644 --- a/lib/shared/mixins/template_mixin.dart +++ b/lib/shared/mixins/template_mixin.dart @@ -38,7 +38,7 @@ mixin Template { if (action == null) return []; return [ IconButton( - onPressed: () async => await showDialog( + onPressed: () async => await showModalBottomSheet( context: context, builder: (context) => action(), ), diff --git a/lib/shared/widgets/read_view.dart b/lib/shared/widgets/read_view.dart index 540431eb..0b94b234 100644 --- a/lib/shared/widgets/read_view.dart +++ b/lib/shared/widgets/read_view.dart @@ -1,6 +1,8 @@ part of 'widgets.dart'; // typedef PDFViewerKey = GlobalKey; +typedef ReadViewController = PdfController; +typedef Document = PdfDocument; abstract interface class Viewer extends StatelessComponent { final String src; @@ -33,12 +35,10 @@ class ReadView extends StatefulWidget { } class ReadViewState extends State { - late PdfController _pdfController; - - Future _initializePdf() async { + Future _initializePdf() async { final file = await downloadPdf(widget.url); - final Future document = PdfDocument.openFile(file.path); - return PdfController(document: document); + final Future document = Document.openFile(file.path); + return ReadViewController(document: document); } Future downloadPdf(String url) async { @@ -106,11 +106,10 @@ class ReadViewState extends State { Widget _buildPDFViewer() => Padding( padding: EdgeInsets.all(10), - child: FutureBuilder( + child: FutureBuilder( future: _initializePdf(), builder: (context, snapshot) { if (!snapshot.hasData) return buildLoadingIndicator(context); - return PdfView( controller: snapshot.data!, renderer: (PdfPage page) => page.render( @@ -120,7 +119,6 @@ class ReadViewState extends State { 10.0, 10.0, page.width * 2, page.height * 2), forPrint: false, quality: 100, - removeTempFile: true, format: PdfPageImageFormat.jpeg, backgroundColor: '#ffffff', ), @@ -130,10 +128,4 @@ class ReadViewState extends State { ); // Widget get progressIndicator => LoadingUtil.buildLoadingIndicator(context); - - @override - void dispose() { - _pdfController.dispose(); - super.dispose(); - } }