diff --git a/example/lib/main.dart b/example/lib/main.dart index a75dd97..6053328 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -29,10 +29,11 @@ class MyApp extends StatelessWidget { }, defaultStyle: theme.textTheme.titleLarge!.copyWith(color: Colors.green), + capitalization: CategoryHeaderCapitalization.uppercase, ), content: [ Category( - name: "Category 1", + name: "category 1", content: [ const Text("Content 1"), Image.network( diff --git a/lib/flutter_nested_categories.dart b/lib/flutter_nested_categories.dart index 4530209..72fb340 100644 --- a/lib/flutter_nested_categories.dart +++ b/lib/flutter_nested_categories.dart @@ -5,5 +5,6 @@ library flutter_nested_categories; export "src/category.dart"; +export "src/category_header_capitalization.dart"; export "src/category_header_styling.dart"; export "src/category_list.dart"; diff --git a/lib/src/category_header_capitalization.dart b/lib/src/category_header_capitalization.dart new file mode 100644 index 0000000..a4d03b6 --- /dev/null +++ b/lib/src/category_header_capitalization.dart @@ -0,0 +1,16 @@ +/// An enum that represents the capitalization of the category header. +/// This is used to determine how the header should be displayed. +/// The header is the name of the category. +enum CategoryHeaderCapitalization { + /// The first letter of the header will be capitalized. + capitalizeFirstLetter, + + /// The header will be displayed in all lowercase. + lowercase, + + /// The header will be displayed in all uppercase. + uppercase, + + /// The header will be displayed as is. + none, +} diff --git a/lib/src/category_header_styling.dart b/lib/src/category_header_styling.dart index e46db5e..337a6a6 100644 --- a/lib/src/category_header_styling.dart +++ b/lib/src/category_header_styling.dart @@ -1,4 +1,5 @@ import "package:flutter/widgets.dart"; +import "package:flutter_nested_categories/src/category_header_capitalization.dart"; /// This class is used to style the headers of the categories in the list. /// The headers are the names of the categories. @@ -8,11 +9,16 @@ class CategoryHeaderStyling { /// is not found in the [headerStyles]. required this.defaultStyle, + /// The capitalization of the headers. This is used to determine how the + /// headers should be displayed. + this.capitalization = CategoryHeaderCapitalization.none, + /// The styles for the headers. The key is the depth of the category. /// The value is the text style for the header. this.headerStyles = const {}, }); final Map headerStyles; + final CategoryHeaderCapitalization capitalization; final TextStyle defaultStyle; } diff --git a/lib/src/category_list.dart b/lib/src/category_list.dart index 28fb394..c8a8b62 100644 --- a/lib/src/category_list.dart +++ b/lib/src/category_list.dart @@ -193,6 +193,23 @@ class _CategoryColumnState extends State<_CategoryColumn> { ); } + String? formatCategoryName() { + var name = widget.category.name; + if (name == null) return null; + + switch (widget.headerStyling?.capitalization) { + case CategoryHeaderCapitalization.capitalizeFirstLetter: + return name[0].toUpperCase() + name.substring(1); + case CategoryHeaderCapitalization.lowercase: + return name.toLowerCase(); + case CategoryHeaderCapitalization.uppercase: + return name.toUpperCase(); + case CategoryHeaderCapitalization.none: + default: + return name; + } + } + Widget _buildCollapsibleHeader(TextStyle styleOfCategory) => InkWell( onTap: () { setState(() { @@ -216,7 +233,7 @@ class _CategoryColumnState extends State<_CategoryColumn> { widget.category.customTitle! else Text( - widget.category.name!, + formatCategoryName()!, style: styleOfCategory, ), ], @@ -229,14 +246,14 @@ class _CategoryColumnState extends State<_CategoryColumn> { child: widget.category.customTitle != null ? widget.category.customTitle! : Text( - widget.category.name!, + formatCategoryName()!, style: styleOfCategory, ), ) : widget.category.customTitle != null ? widget.category.customTitle! : Text( - widget.category.name!, + formatCategoryName()!, style: styleOfCategory, );