-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Presentation] Added initial detail_horizontal_list.dart
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
lib/presentation/shared/details/detail_horizontal_list.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,105 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:shiori/domain/models/models.dart'; | ||
import 'package:shiori/generated/l10n.dart'; | ||
import 'package:shiori/presentation/shared/details/detail_section.dart'; | ||
import 'package:shiori/presentation/shared/images/square_item_image_with_name.dart'; | ||
import 'package:shiori/presentation/shared/utils/size_utils.dart'; | ||
|
||
typedef OnTap = void Function(String key); | ||
|
||
class DetailHorizontalList extends StatelessWidget { | ||
final Color color; | ||
final String title; | ||
final List<ItemCommonWithName> items; | ||
final OnTap onTap; | ||
final VoidCallback onButtonTap; | ||
|
||
const DetailHorizontalList({ | ||
required this.color, | ||
required this.title, | ||
required this.items, | ||
required this.onTap, | ||
required this.onButtonTap, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final s = S.of(context); | ||
return DetailSection.complex( | ||
title: title, | ||
color: color, | ||
children: [ | ||
DetailHorizontalListView( | ||
onTap: onTap, | ||
items: items, | ||
), | ||
DetailHorizontalListButton( | ||
color: color, | ||
title: s.seeAll, | ||
onTap: onButtonTap, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class DetailHorizontalListView extends StatelessWidget { | ||
final List<ItemCommonWithName> items; | ||
final OnTap onTap; | ||
final bool useSmallImageSize; | ||
|
||
const DetailHorizontalListView({ | ||
required this.items, | ||
required this.onTap, | ||
this.useSmallImageSize = false, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final Size size = SizeUtils.getSizeForSquareImages(context, smallImage: useSmallImageSize); | ||
return SizedBox( | ||
height: size.height + 10, | ||
child: ListView.builder( | ||
scrollDirection: Axis.horizontal, | ||
itemCount: items.length, | ||
itemBuilder: (context, index) { | ||
final e = items[index]; | ||
return SquareItemImageWithName( | ||
itemKey: e.key, | ||
name: e.name, | ||
image: e.iconImage, | ||
width: size.width, | ||
height: size.width, | ||
onTap: () => onTap(e.key), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class DetailHorizontalListButton extends StatelessWidget { | ||
final Color color; | ||
final String? title; | ||
final VoidCallback onTap; | ||
|
||
const DetailHorizontalListButton({ | ||
required this.color, | ||
this.title, | ||
required this.onTap, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final s = S.of(context); | ||
return Align( | ||
alignment: Alignment.centerRight, | ||
child: TextButton.icon( | ||
icon: const Icon(Icons.chevron_right), | ||
label: Text(title ?? s.seeAll), | ||
style: TextButton.styleFrom(foregroundColor: color), | ||
onPressed: onTap, | ||
), | ||
); | ||
} | ||
} |