mirror of
https://github.com/Iconica-Development/flutter_nested_categories.git
synced 2025-05-18 23:33:44 +02:00
feat(custom-header): add custom category header functionality
This commit is contained in:
parent
65b958a3e7
commit
8a6adbbee3
2 changed files with 31 additions and 15 deletions
|
@ -7,7 +7,12 @@ import "package:flutter/widgets.dart";
|
|||
class Category {
|
||||
const Category({
|
||||
/// The name of the category.
|
||||
required this.name,
|
||||
this.name,
|
||||
|
||||
/// Optional custom title widget for the category. This will be displayed
|
||||
/// at the top of the category. If set, the text title will be ignored.
|
||||
/// This will be displayed before the content of the category.
|
||||
this.customTitle,
|
||||
|
||||
/// The content of the category. This can be anything, but is usually
|
||||
/// a list of widgets.
|
||||
|
@ -23,9 +28,13 @@ class Category {
|
|||
///
|
||||
/// Default is an empty list.
|
||||
this.nestedCategories = const <Category>[],
|
||||
});
|
||||
}) : assert(
|
||||
name != null || customTitle != null,
|
||||
"A name or a custom title must be set",
|
||||
);
|
||||
|
||||
final String name;
|
||||
final String? name;
|
||||
final Widget? customTitle;
|
||||
final List<Category> nestedCategories;
|
||||
final List<Widget> content;
|
||||
}
|
||||
|
|
|
@ -212,10 +212,13 @@ class _CategoryColumnState extends State<_CategoryColumn> {
|
|||
padding: EdgeInsets.zero,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
widget.category.name,
|
||||
style: styleOfCategory,
|
||||
),
|
||||
if (widget.category.customTitle != null)
|
||||
widget.category.customTitle!
|
||||
else
|
||||
Text(
|
||||
widget.category.name!,
|
||||
style: styleOfCategory,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -223,15 +226,19 @@ class _CategoryColumnState extends State<_CategoryColumn> {
|
|||
Widget _buildNonCollapsibleHeader(TextStyle styleOfCategory) =>
|
||||
widget.headerCentered
|
||||
? Center(
|
||||
child: Text(
|
||||
widget.category.name,
|
||||
style: styleOfCategory,
|
||||
),
|
||||
child: widget.category.customTitle != null
|
||||
? widget.category.customTitle!
|
||||
: Text(
|
||||
widget.category.name!,
|
||||
style: styleOfCategory,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
widget.category.name,
|
||||
style: styleOfCategory,
|
||||
);
|
||||
: widget.category.customTitle != null
|
||||
? widget.category.customTitle!
|
||||
: Text(
|
||||
widget.category.name!,
|
||||
style: styleOfCategory,
|
||||
);
|
||||
|
||||
Widget _buildNestedCategoryList() => CategoryList(
|
||||
content: widget.category.nestedCategories,
|
||||
|
|
Loading…
Reference in a new issue