This commit is contained in:
jantunesmessias 2025-02-26 14:41:28 -03:00
parent a7f1ea418b
commit 203632bbdf
3 changed files with 39 additions and 24 deletions

View File

@ -131,7 +131,7 @@ class DocumentManagerScreen extends StatelessScreen {
children: [
Expanded(
child: EnhancedListView<Document, SearchField, Category, Query>(
key: model.vehicleScreenManager,
key: model.enhancedListViewKey,
controller: controller,
repository: repository,
),
@ -240,25 +240,25 @@ class DocumentModel extends FlutterFlowModel<DocumentPage> {
DocumentModel(this.bloc);
late EnhancedListViewKey<Document, SearchField, Category, Query>
vehicleScreenManager;
late DocumentKey vehicleScreenViewer;
enhancedListViewKey;
late EnhancedCarouselViewKey<Category> carouselViewKey;
late bool categoryIsSelected;
late DocumentKey vehicleScreenViewer;
/// ------------
@override
void initState(BuildContext context) {
vehicleScreenManager =
enhancedListViewKey =
EnhancedListViewKey<Document, SearchField, Category, Query>();
carouselViewKey = EnhancedCarouselViewKey<Category>();
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<DocumentPage> {
}
return EnhancedCarouselView<T>(
key: carouselViewKey,
dataProvider: fetchData,
itemBuilder: categoryItemBuilder,
filter: filterByCategory<T>,
@ -454,18 +455,14 @@ class DocumentModel extends FlutterFlowModel<DocumentPage> {
/// [Filter]
void filterBySearchBar<T>(T query, BuildContext context) {
final key = vehicleScreenManager.currentState;
return key?.filterBodyItems(query);
final enhancedListViewState = enhancedListViewKey.currentState;
return enhancedListViewState?.filterBodyItems(query);
}
void filterByCategory<T>(T query, BuildContext context) {
final key = vehicleScreenManager.currentState;
void filterByCategory<T>(T? query, BuildContext context) {
final enhancedListViewState = enhancedListViewKey.currentState;
categoryIsSelected
? key?.filterBodyItems(null)
: key?.filterBodyItems(query);
categoryIsSelected = !categoryIsSelected;
enhancedListViewState?.filterBodyItems(query);
}
/// [Exception]

View File

@ -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<T> = GlobalKey<_EnhancedCarouselViewState<T>>;
class EnhancedCarouselView<T> extends StatefulWidget {
final Future<List<T?>> Function() dataProvider;
final void Function(T, BuildContext) filter;
final void Function(T?, BuildContext) filter;
final Widget Function<T>(T? item, bool isSelected) itemBuilder;
final bool showIndicator;
@ -24,6 +28,10 @@ class EnhancedCarouselView<T> extends StatefulWidget {
class _EnhancedCarouselViewState<T> extends State<EnhancedCarouselView<T>> {
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<T> extends State<EnhancedCarouselView<T>> {
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<T> extends State<EnhancedCarouselView<T>> {
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,
),

View File

@ -122,7 +122,9 @@ class ReadViewState extends State<ReadView> {
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}');