import 'package:didvan/constants/assets.dart'; import 'package:didvan/config/theme_data.dart'; import 'package:didvan/routes/routes.dart'; import 'package:didvan/views/widgets/search_field.dart'; import 'package:didvan/views/home/home_state.dart'; import 'package:didvan/utils/action_sheet.dart'; import 'package:didvan/models/view/action_sheet_data.dart'; import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/views/widgets/didvan/checkbox.dart'; import 'package:didvan/views/widgets/item_title.dart'; import 'package:didvan/views/widgets/date_picker_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:provider/provider.dart'; class HomeAppBar extends StatelessWidget { final bool showBackButton; final String? title; final bool showSearchField; const HomeAppBar({ super.key, this.showBackButton = false, this.title, this.showSearchField = false, }); @override Widget build(BuildContext context) { return Column( children: [ Padding( padding: const EdgeInsets.fromLTRB(16, 0, 16, 16), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ if (showBackButton) GestureDetector( onTap: () => Navigator.pop(context), child: Container( width: 44, height: 44, decoration: BoxDecoration( color: Theme.of(context).colorScheme.surface, borderRadius: BorderRadius.circular(12), border: Border.all( color: Theme.of(context).colorScheme.outline.withOpacity(0.2), ), ), child: Center( child: Icon( Icons.arrow_back_ios_new, size: 20, color: Theme.of(context).colorScheme.title, ), ), ), ) else SvgPicture.asset( Assets.horizontalLogoWithText, height: 60, color: Theme.of(context).colorScheme.title, ), if (title != null && showBackButton) Expanded( child: Center( child: Text( title!, style: Theme.of(context).textTheme.titleLarge?.copyWith( fontWeight: FontWeight.w600, color: Theme.of(context).colorScheme.title, ), ), ), ), GestureDetector( onTap: () { Navigator.pushNamed(context, Routes.profile); }, child: SizedBox( width: 44, height: 44, child: Center( child: SvgPicture.asset( 'lib/assets/icons/New_Profile.svg', width: 30, height: 30, ), ), ), ), ], ), ).animate() .fadeIn(duration: 500.ms) .slideY(begin: -0.5, duration: 500.ms), if (showSearchField) Padding( padding: const EdgeInsets.fromLTRB(16, 0, 16, 16), child: SearchField( title: 'دیدوان', focusNode: context.read().searchFieldFocusNode, onChanged: (value) { final homeState = context.read(); if (value.length >= 2) { homeState.onSearchChanged(value); } else if (value.isEmpty) { homeState.clearSearch(); } }, onFilterButtonPressed: () => _showFilterBottomSheet(context), isFiltered: context.watch().filtering, value: context.watch().search, extraIconPath: 'lib/assets/icons/profile.svg', onExtraIconPressed: () { print('Extra icon pressed!'); }, ), ).animate().fadeIn(delay: 200.ms, duration: 500.ms), ], ); } Future _showFilterBottomSheet(BuildContext context) async { final state = Provider.of(context, listen: false); ActionSheetUtils(context).showBottomSheet( data: ActionSheetData( titleIcon: DidvanIcons.filter_regular, dismissTitle: 'حذف فیلتر', confrimTitle: 'نمایش نتایج', onDismissed: () => state.resetFilters(false), onConfirmed: () => state.searchAll(page: 1), content: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (state.currentPageIndex != 3) ...[ ItemTitle( title: 'تاریخ ایجاد', style: Theme.of(context).textTheme.bodyMedium, icon: DidvanIcons.calendar_range_regular, ), const SizedBox(height: 8), StatefulBuilder( builder: (context, setState) => Row( children: [ DatePickerButton( initialValue: state.startDate, emptyText: 'از تاریخ', onPicked: (date) => setState(() => state.startDate = date), lastDate: state.endDate, ), const SizedBox(width: 8), DatePickerButton( initialValue: state.endDate, emptyText: 'تا تاریخ', onPicked: (date) => setState(() => state.endDate = date), firstDate: state.startDate, ), ], ), ), const SizedBox(height: 28), ], ItemTitle( title: 'دسته بندی', icon: DidvanIcons.category_regular, style: Theme.of(context).textTheme.bodyMedium, ), const SizedBox(height: 12), Wrap( children: [ for (var i = 0; i < state.categoryFilters.length; i++) if (state.categoryFilters[i].label != 'هوشان') SizedBox( width: (MediaQuery.of(context).size.width - 40) / 2, child: DidvanCheckbox( title: state.categoryFilters[i].label, value: state.selectedCats .contains(state.categoryFilters[i]), onChanged: (value) { if (value) { state.selectedCats.add(state.categoryFilters[i]); return; } state.selectedCats.remove(state.categoryFilters[i]); }, ), ), ], ), ], ), ), ); } }