-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
sliver_today_main_title.dart
61 lines (57 loc) · 2.11 KB
/
sliver_today_main_title.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/presentation/home/widgets/change_current_day_dialog.dart';
import 'package:shiori/presentation/shared/loading.dart';
import 'package:shiori/presentation/shared/styles.dart';
class SliverTodayMainTitle extends StatelessWidget {
const SliverTodayMainTitle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
return SliverPadding(
padding: const EdgeInsets.only(top: 10),
sliver: SliverToBoxAdapter(
child: BlocBuilder<HomeBloc, HomeState>(
builder: (ctx, state) => state.map(
loading: (_) => const Loading(useScaffold: false),
loaded: (state) => Container(
margin: Styles.edgeInsetHorizontal16,
child: RichText(
text: TextSpan(
text: s.todayAscensionMaterials,
style: theme.textTheme.headline6!.copyWith(fontWeight: FontWeight.bold),
children: <TextSpan>[
TextSpan(
text: ' [ ${state.dayName} ]',
style: theme.textTheme.caption,
recognizer: TapGestureRecognizer()..onTap = () => _openDayWeekDialog(state.day, context),
),
],
),
),
),
),
),
),
);
}
Future<void> _openDayWeekDialog(int currentSelectedDay, BuildContext context) async {
await showDialog<int>(
context: context,
builder: (_) => ChangeCurrentDayDialog(currentSelectedDay: currentSelectedDay),
).then((selectedDay) {
if (selectedDay == null) {
return;
}
if (selectedDay < 0) {
context.read<HomeBloc>().add(const HomeEvent.init());
} else {
context.read<HomeBloc>().add(HomeEvent.dayChanged(newDay: selectedDay));
}
});
}
}