diff --git a/lib/src/category.dart b/lib/src/category.dart index d99cb17..3ac01ab 100644 --- a/lib/src/category.dart +++ b/lib/src/category.dart @@ -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 [], - }); + }) : 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 nestedCategories; final List content; } diff --git a/lib/src/category_list.dart b/lib/src/category_list.dart index ad7b6db..28fb394 100644 --- a/lib/src/category_list.dart +++ b/lib/src/category_list.dart @@ -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,