-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
characters_per_region_dialog.dart
67 lines (64 loc) · 2.52 KB
/
characters_per_region_dialog.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
62
63
64
65
66
67
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shiori/application/bloc.dart';
import 'package:shiori/domain/enums/enums.dart';
import 'package:shiori/generated/l10n.dart';
import 'package:shiori/injection.dart';
import 'package:shiori/presentation/shared/dialogs/dialog_list_item_row.dart';
import 'package:shiori/presentation/shared/extensions/i18n_extensions.dart';
import 'package:shiori/presentation/shared/extensions/media_query_extensions.dart';
import 'package:shiori/presentation/shared/loading.dart';
import 'package:shiori/presentation/shared/nothing_found_column.dart';
class CharactersPerRegionDialog extends StatelessWidget {
final RegionType regionType;
const CharactersPerRegionDialog({
Key? key,
required this.regionType,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
final mq = MediaQuery.of(context);
return BlocProvider<CharactersPerRegionBloc>(
create: (context) => Injection.charactersPerRegionBloc..add(CharactersPerRegionEvent.init(type: regionType)),
child: AlertDialog(
title: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
s.translateRegionType(regionType),
overflow: TextOverflow.ellipsis,
),
Text(
s.characters,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.caption,
),
],
),
actions: [
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text(s.ok),
)
],
content: BlocBuilder<CharactersPerRegionBloc, CharactersPerRegionState>(
builder: (context, state) => state.maybeMap(
loaded: (state) => state.items.isEmpty
? const NothingFoundColumn(mainAxisSize: MainAxisSize.min)
: SizedBox(
height: mq.getHeightForDialogs(state.items.length + 1),
width: mq.getWidthForDialogs(),
child: ListView.builder(
itemCount: state.items.length,
itemBuilder: (context, index) => DialogListItemRow.fromItem(itemType: ItemType.character, item: state.items[index]),
),
),
orElse: () => const Loading(useScaffold: false, mainAxisSize: MainAxisSize.min),
),
),
),
);
}
}