Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
time_ranges_field.dart
Go to the documentation of this file.
1import 'package:connect/core/localization/app_localizations.dart';
2
3import '/features/collections/domain/entities/collection_entity.dart';
4import '/features/collections/presentation/logic/proposed_times_cubit/proposed_times_cubit.dart';
5import 'package:flutter/material.dart';
6import 'package:flutter_bloc/flutter_bloc.dart';
7import 'package:flutter_screenutil/flutter_screenutil.dart';
8import 'package:hugeicons/hugeicons.dart';
9
12 super.key,
13 required this.selectedTimeRange,
14 required this.onPickTimeRange,
15 });
16
18 final Function(ProposedTimeEntity pickedTimeRange) onPickTimeRange;
19
20 @override
21 State<TimeRangeField> createState() => _TimeRangeFieldState();
22}
23
24class _TimeRangeFieldState extends State<TimeRangeField> {
25 @override
26 void initState() {
27 context.read<ProposedTimesCubit>().loadProposedTimes();
28 super.initState();
29 }
30
31 @override
32 Widget build(BuildContext context) {
33 return BlocBuilder<ProposedTimesCubit, ProposedTimesState>(
34 builder: (context, state) {
35 return Container(
36 padding: EdgeInsets.symmetric(horizontal: 15.sp),
37 decoration: BoxDecoration(
38 borderRadius: BorderRadius.circular(10),
39 color: Theme.of(context).colorScheme.surface,
40 ),
41 child: _adaptChilftoState(state, context),
42 );
43 },
44 );
45 }
46
47 _adaptChilftoState(ProposedTimesState state, BuildContext context) {
48 if (state is ProposedTimesLoadedState) {
49 return DropdownButton<ProposedTimeEntity>(
50 padding: EdgeInsets.zero,
51 value: widget.selectedTimeRange,
52 hint: Text(
53 AppLocalizations.of(context).translate('select range'),
54 style: Theme.of(context).textTheme.bodySmall,
55 ),
56 underline: const SizedBox(),
57 style: Theme.of(context).textTheme.bodySmall,
58 onChanged: (ProposedTimeEntity? timeRange) {
59 if (timeRange != null) {
60 widget.onPickTimeRange(timeRange);
61 }
62 },
63 dropdownColor: Theme.of(context).colorScheme.surface,
64 iconEnabledColor: Theme.of(context).colorScheme.onSurface,
65 icon: Icon(
66 HugeIcons.strokeRoundedArrowDown01,
67 size: 14.sp,
68 ),
69 items: state.times.map((ProposedTimeEntity time) {
70 return DropdownMenuItem<ProposedTimeEntity>(
71 value: time,
72 child: Text(
73 time.name ?? '',
74 ),
75 );
76 }).toList(),
77 );
78 }
79 if (state is ProposedTimesLoadingState) {
80 return const CircularProgressIndicator();
81 } else {
82 return const SizedBox();
83 }
84 }
85}
String translate(String key)
static AppLocalizations of(BuildContext context)
final List< ProposedTimeEntity > times
override State< TimeRangeField > createState()
final ProposedTimeEntity selectedTimeRange
final Function(ProposedTimeEntity pickedTimeRange) onPickTimeRange
const TimeRangeField({ super.key, required this.selectedTimeRange, required this.onPickTimeRange, })
ProposedTimeEntity({ required this.id, required this.name, })
final Widget child
final EdgeInsets padding
override void initState()
final Color color
Definition failures.dart:1
override Widget build(BuildContext context)
final double value
_adaptChilftoState(ProposedTimesState state, BuildContext context)
const TimeRangeField({ super.key, required this.selectedTimeRange, required this.onPickTimeRange, })