import 'package:flutter/material.dart'; import 'package:frontend_eccp_mobile/app/core/constants/constants.dart'; import 'package:frontend_eccp_mobile/app/core/widgets/app_empty.dart'; import 'package:frontend_eccp_mobile/app/core/widgets/layout/app_screen.dart'; import 'package:frontend_eccp_mobile/modules/berkas/data/models/berkas_model.dart'; import 'package:frontend_eccp_mobile/modules/berkas/presentation/widgets/berkas_item_card.dart'; import 'package:frontend_eccp_mobile/modules/berkas/presentation/widgets/berkas_section_head.dart'; import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart'; class BerkasPage extends StatefulWidget { const BerkasPage({super.key}); @override State createState() => _BerkasPageState(); } class _BerkasPageState extends State { final RefreshController _refreshController = RefreshController(); Future _onRefresh() async { await Future.delayed(const Duration(seconds: 1)); _refreshController.refreshCompleted(); } @override void dispose() { _refreshController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return AppScreen( title: 'Berkas', backgroundColor: AppColors.neutral50, scrollableBody: false, useShadowAppBar: false, isSliver: true, refreshController: _refreshController, enablePullDown: true, onRefresh: _onRefresh, body: const SizedBox.shrink(), slivers: [ if (todayBerkas.isNotEmpty) _buildSection( title: 'Terbaru', items: todayBerkas, ), if (earlierBerkas.isNotEmpty) _buildSection( title: 'Lebih Lama', items: earlierBerkas, ), if (todayBerkas.isEmpty && earlierBerkas.isEmpty) SliverToBoxAdapter( child: SizedBox( height: MediaQuery.of(context).size.height * 0.7, child: Center( child: empty(), ), ), ), const SliverToBoxAdapter(child: AppSpacing.h24), ], ); } SliverMainAxisGroup _buildSection({ required String title, required List items, }) { return SliverMainAxisGroup( slivers: [ SliverPersistentHeader( pinned: true, delegate: BerkasSectionHeaderDelegate(title: title), ), SliverPadding( padding: const EdgeInsets.symmetric( horizontal: AppSizes.s16, ), sliver: SliverToBoxAdapter( child: Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 900), child: Column( children: List.generate(items.length, (index) { final item = items[index]; return Padding( padding: AppPadding.t8, child: BerkasItemCard(item: item), ); }), ), ), ), ), ), const SliverToBoxAdapter(child: AppSpacing.h16), ], ); } } final todayBerkas = [ BerkasModel( title: 'Rosaldo', description: '2908388', ), BerkasModel( title: 'Rosaldo', description: '2908388', ), BerkasModel( title: 'Rosaldo', description: '2908388', ), BerkasModel( title: 'Rosaldo', description: '2908388', ), BerkasModel( title: 'Rosaldo', description: '2908388', ), BerkasModel( title: 'Rosaldo', description: '2908388', ), ]; final earlierBerkas = [ BerkasModel( title: 'Rosaldo 2', description: '2908389', ), BerkasModel( title: 'Rosaldo 3', description: '2928389', ), BerkasModel( title: 'Rosaldo 4', description: '2900389', ), BerkasModel( title: 'Rosaldo 5', description: '3908389', ), BerkasModel( title: 'Rosaldo 2', description: '2908389', ), BerkasModel( title: 'Rosaldo 3', description: '2928389', ), BerkasModel( title: 'Rosaldo 4', description: '2900389', ), BerkasModel( title: 'Rosaldo 5', description: '3908389', ), BerkasModel( title: 'Rosaldo 2', description: '2908389', ), BerkasModel( title: 'Rosaldo 3', description: '2928389', ), BerkasModel( title: 'Rosaldo 4', description: '2900389', ), BerkasModel( title: 'Rosaldo 5', description: '3908389', ), ];