Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Presentation] Added a characters per region chart + dialog
- Loading branch information
Showing
9 changed files
with
216 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
lib/presentation/shared/dialogs/characters_per_region_dialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
: 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), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:shiori/domain/enums/enums.dart'; | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/presentation/shared/images/circle_character.dart'; | ||
import 'package:shiori/presentation/shared/images/circle_weapon.dart'; | ||
import 'package:shiori/presentation/shared/styles.dart'; | ||
|
||
typedef RowEndWidget = Widget Function(String); | ||
|
||
class DialogListItemRow extends StatelessWidget { | ||
final ItemType itemType; | ||
final String itemKey; | ||
final String image; | ||
final String name; | ||
final RowEndWidget? getRowEndWidget; | ||
|
||
const DialogListItemRow({ | ||
Key? key, | ||
required this.itemType, | ||
required this.itemKey, | ||
required this.image, | ||
required this.name, | ||
this.getRowEndWidget, | ||
}) : assert(itemType == ItemType.character || itemType == ItemType.weapon), | ||
super(key: key); | ||
|
||
DialogListItemRow.fromItem({ | ||
Key? key, | ||
required ItemType itemType, | ||
required ItemCommonWithName item, | ||
RowEndWidget? getRightWidget, | ||
}) : this(key: key, itemType: itemType, itemKey: item.key, image: item.image, name: item.name, getRowEndWidget: getRightWidget); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Row( | ||
children: [ | ||
if (itemType == ItemType.character) | ||
CircleCharacter(itemKey: itemKey, image: image, radius: 40) | ||
else | ||
CircleWeapon(itemKey: itemKey, image: image, radius: 40), | ||
Expanded( | ||
child: Padding( | ||
padding: Styles.edgeInsetHorizontal16, | ||
child: getRowEndWidget != null | ||
? getRowEndWidget!.call(itemKey) | ||
: Text( | ||
name, | ||
overflow: TextOverflow.ellipsis, | ||
maxLines: 2, | ||
style: theme.textTheme.subtitle1, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
const Divider(), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.