mirror of
https://github.com/Iconica-Development/flutter_nested_categories.git
synced 2025-05-18 23:33:44 +02:00
feat(capitalization): add header capitalization
This commit is contained in:
parent
6ddabf3ed7
commit
80a6f97dca
5 changed files with 45 additions and 4 deletions
|
@ -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(
|
||||
|
|
|
@ -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";
|
||||
|
|
16
lib/src/category_header_capitalization.dart
Normal file
16
lib/src/category_header_capitalization.dart
Normal file
|
@ -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,
|
||||
}
|
|
@ -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<int, TextStyle?> headerStyles;
|
||||
final CategoryHeaderCapitalization capitalization;
|
||||
final TextStyle defaultStyle;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue