fix
This commit is contained in:
parent
a7f1ea418b
commit
203632bbdf
|
@ -131,7 +131,7 @@ class DocumentManagerScreen extends StatelessScreen {
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: EnhancedListView<Document, SearchField, Category, Query>(
|
child: EnhancedListView<Document, SearchField, Category, Query>(
|
||||||
key: model.vehicleScreenManager,
|
key: model.enhancedListViewKey,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
repository: repository,
|
repository: repository,
|
||||||
),
|
),
|
||||||
|
@ -240,25 +240,25 @@ class DocumentModel extends FlutterFlowModel<DocumentPage> {
|
||||||
DocumentModel(this.bloc);
|
DocumentModel(this.bloc);
|
||||||
|
|
||||||
late EnhancedListViewKey<Document, SearchField, Category, Query>
|
late EnhancedListViewKey<Document, SearchField, Category, Query>
|
||||||
vehicleScreenManager;
|
enhancedListViewKey;
|
||||||
late DocumentKey vehicleScreenViewer;
|
late EnhancedCarouselViewKey<Category> carouselViewKey;
|
||||||
|
|
||||||
late bool categoryIsSelected;
|
late DocumentKey vehicleScreenViewer;
|
||||||
|
|
||||||
/// ------------
|
/// ------------
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState(BuildContext context) {
|
void initState(BuildContext context) {
|
||||||
vehicleScreenManager =
|
enhancedListViewKey =
|
||||||
EnhancedListViewKey<Document, SearchField, Category, Query>();
|
EnhancedListViewKey<Document, SearchField, Category, Query>();
|
||||||
|
carouselViewKey = EnhancedCarouselViewKey<Category>();
|
||||||
vehicleScreenViewer = DocumentKey();
|
vehicleScreenViewer = DocumentKey();
|
||||||
|
|
||||||
categoryIsSelected = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
vehicleScreenManager.currentState?.dispose();
|
enhancedListViewKey.currentState?.dispose();
|
||||||
|
carouselViewKey.currentState?.dispose();
|
||||||
vehicleScreenViewer.currentState?.dispose();
|
vehicleScreenViewer.currentState?.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,6 +338,7 @@ class DocumentModel extends FlutterFlowModel<DocumentPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return EnhancedCarouselView<T>(
|
return EnhancedCarouselView<T>(
|
||||||
|
key: carouselViewKey,
|
||||||
dataProvider: fetchData,
|
dataProvider: fetchData,
|
||||||
itemBuilder: categoryItemBuilder,
|
itemBuilder: categoryItemBuilder,
|
||||||
filter: filterByCategory<T>,
|
filter: filterByCategory<T>,
|
||||||
|
@ -454,18 +455,14 @@ class DocumentModel extends FlutterFlowModel<DocumentPage> {
|
||||||
/// [Filter]
|
/// [Filter]
|
||||||
|
|
||||||
void filterBySearchBar<T>(T query, BuildContext context) {
|
void filterBySearchBar<T>(T query, BuildContext context) {
|
||||||
final key = vehicleScreenManager.currentState;
|
final enhancedListViewState = enhancedListViewKey.currentState;
|
||||||
return key?.filterBodyItems(query);
|
return enhancedListViewState?.filterBodyItems(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void filterByCategory<T>(T query, BuildContext context) {
|
void filterByCategory<T>(T? query, BuildContext context) {
|
||||||
final key = vehicleScreenManager.currentState;
|
final enhancedListViewState = enhancedListViewKey.currentState;
|
||||||
|
|
||||||
categoryIsSelected
|
enhancedListViewState?.filterBodyItems(query);
|
||||||
? key?.filterBodyItems(null)
|
|
||||||
: key?.filterBodyItems(query);
|
|
||||||
|
|
||||||
categoryIsSelected = !categoryIsSelected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Exception]
|
/// [Exception]
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hub/flutter_flow/index.dart';
|
import 'package:hub/flutter_flow/index.dart';
|
||||||
import 'package:hub/shared/utils.dart';
|
import 'package:hub/shared/utils.dart';
|
||||||
|
|
||||||
|
typedef EnhancedCarouselViewKey<T> = GlobalKey<_EnhancedCarouselViewState<T>>;
|
||||||
|
|
||||||
class EnhancedCarouselView<T> extends StatefulWidget {
|
class EnhancedCarouselView<T> extends StatefulWidget {
|
||||||
final Future<List<T?>> Function() dataProvider;
|
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 Widget Function<T>(T? item, bool isSelected) itemBuilder;
|
||||||
final bool showIndicator;
|
final bool showIndicator;
|
||||||
|
|
||||||
|
@ -24,6 +28,10 @@ class EnhancedCarouselView<T> extends StatefulWidget {
|
||||||
class _EnhancedCarouselViewState<T> extends State<EnhancedCarouselView<T>> {
|
class _EnhancedCarouselViewState<T> extends State<EnhancedCarouselView<T>> {
|
||||||
T? selectedCategory;
|
T? selectedCategory;
|
||||||
|
|
||||||
|
bool itemIsSelected(T item) {
|
||||||
|
return selectedCategory == item;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = FlutterFlowTheme.of(context);
|
final theme = FlutterFlowTheme.of(context);
|
||||||
|
@ -56,7 +64,7 @@ class _EnhancedCarouselViewState<T> extends State<EnhancedCarouselView<T>> {
|
||||||
if (!snapshot.hasData) return SizedBox();
|
if (!snapshot.hasData) return SizedBox();
|
||||||
final items = snapshot.data!
|
final items = snapshot.data!
|
||||||
.map((item) =>
|
.map((item) =>
|
||||||
widget.itemBuilder(item, item == selectedCategory))
|
widget.itemBuilder(item, itemIsSelected(item as T)))
|
||||||
.toList();
|
.toList();
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 130, // Set a specific height
|
height: 130, // Set a specific height
|
||||||
|
@ -74,14 +82,22 @@ class _EnhancedCarouselViewState<T> extends State<EnhancedCarouselView<T>> {
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
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(() {
|
setState(() {
|
||||||
if (selectedCategory == snapshot.data![index])
|
if (isSame) {
|
||||||
selectedCategory = null;
|
selectedCategory = null;
|
||||||
else
|
} else {
|
||||||
selectedCategory = snapshot.data![index] as T;
|
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,
|
children: items,
|
||||||
),
|
),
|
||||||
|
|
|
@ -122,7 +122,9 @@ class ReadViewState extends State<ReadView> {
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final XFile xfile = XFile.fromData(response.bodyBytes,
|
final XFile xfile = XFile.fromData(response.bodyBytes,
|
||||||
name: '${widget.title}.pdf', mimeType: 'application/pdf');
|
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 {
|
} else {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'Erro ao compartilhar o arquivo: ${response.statusCode}');
|
'Erro ao compartilhar o arquivo: ${response.statusCode}');
|
||||||
|
|
Loading…
Reference in New Issue