72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hub/flutter_flow/index.dart';
|
|
import 'package:hub/shared/utils.dart';
|
|
|
|
class EnhancedCarouselView<T> extends StatelessWidget {
|
|
final Future<List<T?>> Function() dataProvider;
|
|
final void Function(T, BuildContext) filter;
|
|
final Widget Function<T>(T? item) itemBuilder;
|
|
|
|
const EnhancedCarouselView({
|
|
super.key,
|
|
required this.dataProvider,
|
|
required this.filter,
|
|
required this.itemBuilder,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = FlutterFlowTheme.of(context);
|
|
final backgroundColor = theme.primary;
|
|
final overlayColor = WidgetStateProperty.all(Colors.transparent);
|
|
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
spacing: 20,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(15, 0, 50, 0),
|
|
child: Text(
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Suas Categorias',
|
|
enText: 'Your Categories',
|
|
),
|
|
style: TextStyle(
|
|
color: FlutterFlowTheme.of(context).primaryText,
|
|
fontSize: LimitedFontSizeUtil.getHeaderFontSize(context),
|
|
),
|
|
),
|
|
),
|
|
FutureBuilder<List<T?>>(
|
|
future: dataProvider(),
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) return SizedBox();
|
|
final items =
|
|
snapshot.data!.map((item) => itemBuilder(item)).toList();
|
|
return SizedBox(
|
|
height: 130, // Set a specific height
|
|
child: CarouselView(
|
|
itemExtent: 140,
|
|
enableSplash: true,
|
|
itemSnapping: true,
|
|
controller: CarouselController(initialItem: 1),
|
|
backgroundColor: backgroundColor,
|
|
overlayColor: overlayColor,
|
|
padding: EdgeInsets.zero,
|
|
elevation: 0,
|
|
shrinkExtent: 10,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
onTap: (index) => filter(snapshot.data![index] as T, context),
|
|
children: items,
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
);
|
|
}
|
|
}
|