diff --git a/lib/features/documents/documents.dart b/lib/features/documents/documents.dart index 1b84a344..1373641d 100644 --- a/lib/features/documents/documents.dart +++ b/lib/features/documents/documents.dart @@ -131,7 +131,7 @@ class DocumentManagerScreen extends StatelessScreen { children: [ Expanded( child: EnhancedListView( - key: model.vehicleScreenManager, + key: model.enhancedListViewKey, controller: controller, repository: repository, ), @@ -240,25 +240,25 @@ class DocumentModel extends FlutterFlowModel { DocumentModel(this.bloc); late EnhancedListViewKey - vehicleScreenManager; - late DocumentKey vehicleScreenViewer; + enhancedListViewKey; + late EnhancedCarouselViewKey carouselViewKey; - late bool categoryIsSelected; + late DocumentKey vehicleScreenViewer; /// ------------ @override void initState(BuildContext context) { - vehicleScreenManager = + enhancedListViewKey = EnhancedListViewKey(); + carouselViewKey = EnhancedCarouselViewKey(); vehicleScreenViewer = DocumentKey(); - - categoryIsSelected = false; } @override void dispose() { - vehicleScreenManager.currentState?.dispose(); + enhancedListViewKey.currentState?.dispose(); + carouselViewKey.currentState?.dispose(); vehicleScreenViewer.currentState?.dispose(); } @@ -338,6 +338,7 @@ class DocumentModel extends FlutterFlowModel { } return EnhancedCarouselView( + key: carouselViewKey, dataProvider: fetchData, itemBuilder: categoryItemBuilder, filter: filterByCategory, @@ -454,18 +455,14 @@ class DocumentModel extends FlutterFlowModel { /// [Filter] void filterBySearchBar(T query, BuildContext context) { - final key = vehicleScreenManager.currentState; - return key?.filterBodyItems(query); + final enhancedListViewState = enhancedListViewKey.currentState; + return enhancedListViewState?.filterBodyItems(query); } - void filterByCategory(T query, BuildContext context) { - final key = vehicleScreenManager.currentState; + void filterByCategory(T? query, BuildContext context) { + final enhancedListViewState = enhancedListViewKey.currentState; - categoryIsSelected - ? key?.filterBodyItems(null) - : key?.filterBodyItems(query); - - categoryIsSelected = !categoryIsSelected; + enhancedListViewState?.filterBodyItems(query); } /// [Exception] diff --git a/lib/shared/widgets/enhanced_carousel_view.dart b/lib/shared/widgets/enhanced_carousel_view.dart index 6cb3a1b1..c031172b 100644 --- a/lib/shared/widgets/enhanced_carousel_view.dart +++ b/lib/shared/widgets/enhanced_carousel_view.dart @@ -1,10 +1,14 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/index.dart'; import 'package:hub/shared/utils.dart'; +typedef EnhancedCarouselViewKey = GlobalKey<_EnhancedCarouselViewState>; + class EnhancedCarouselView extends StatefulWidget { final Future> Function() dataProvider; - final void Function(T, BuildContext) filter; + final void Function(T?, BuildContext) filter; final Widget Function(T? item, bool isSelected) itemBuilder; final bool showIndicator; @@ -24,6 +28,10 @@ class EnhancedCarouselView extends StatefulWidget { class _EnhancedCarouselViewState extends State> { T? selectedCategory; + bool itemIsSelected(T item) { + return selectedCategory == item; + } + @override Widget build(BuildContext context) { final theme = FlutterFlowTheme.of(context); @@ -56,7 +64,7 @@ class _EnhancedCarouselViewState extends State> { if (!snapshot.hasData) return SizedBox(); final items = snapshot.data! .map((item) => - widget.itemBuilder(item, item == selectedCategory)) + widget.itemBuilder(item, itemIsSelected(item as T))) .toList(); return SizedBox( height: 130, // Set a specific height @@ -74,14 +82,22 @@ class _EnhancedCarouselViewState extends State> { shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), - onTap: (index) { + onTap: (index) async { + log('Selected: ${snapshot.data![index]}'); + log('Selected Category: $selectedCategory'); + final bool isSame = + itemIsSelected(snapshot.data![index]!); setState(() { - if (selectedCategory == snapshot.data![index]) + if (isSame) { selectedCategory = null; - else + } else { selectedCategory = snapshot.data![index] as T; + } }); - widget.filter(snapshot.data![index] as T, context); + if (isSame) + widget.filter(null, context); + else + widget.filter(snapshot.data![index] as T, context); }, children: items, ), diff --git a/lib/shared/widgets/read_view.dart b/lib/shared/widgets/read_view.dart index 8be31b52..4cd5a806 100644 --- a/lib/shared/widgets/read_view.dart +++ b/lib/shared/widgets/read_view.dart @@ -122,7 +122,9 @@ class ReadViewState extends State { if (response.statusCode == 200) { final XFile xfile = XFile.fromData(response.bodyBytes, name: '${widget.title}.pdf', mimeType: 'application/pdf'); - await Share.shareXFiles([xfile], text: 'Confira este PDF!'); + await Share.shareXFiles([xfile], + text: 'Confira este PDF!', + fileNameOverrides: ['${widget.title}.pdf']); } else { throw Exception( 'Erro ao compartilhar o arquivo: ${response.statusCode}');