Skip to content

Commit

Permalink
Merge pull request #42 from shiburagi/feature_suffix_prefix
Browse files Browse the repository at this point in the history
prefix and suffix for MenuItem
  • Loading branch information
shiburagi authored Mar 10, 2021
2 parents 733b52b + 955cece commit d8c5f7f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.1.0
* Prefix and suffix attribute

# 2.0.0+4
* Change minimum version for dart

Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,24 @@ new DrawerScaffold(
```dart
new DrawerScaffold(
headerView: headerView(context),
itemBuilder:
(BuildContext context, MenuItem menuItem, bool isSelected) {
return Container(
color: isSelected
? Theme.of(context).accentColor.withOpacity(0.7)
: Colors.transparent,
padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
child: Text(
menuItem.title,
style: Theme.of(context).textTheme.subhead?.copyWith(
color: isSelected ? Colors.black87 : Colors.white70),
),
);
}
drawers: [
SideDrawer(
itemBuilder:
(BuildContext context, MenuItem menuItem, bool isSelected) {
return Container(
color: isSelected
? Theme.of(context).accentColor.withOpacity(0.7)
: Colors.transparent,
padding: EdgeInsets.fromLTRB(24, 16, 24, 16),
child: Text(
menuItem.title,
style: Theme.of(context).textTheme.subhead?.copyWith(
color: isSelected ? Colors.black87 : Colors.white70),
),
);
}
)
],
...
);
```
Expand Down
3 changes: 0 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
/* Begin XCBuildConfiguration section */
249021D3217E4FDB00AE95B9 /* Profile */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -318,7 +317,6 @@
};
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -374,7 +372,6 @@
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions example/lib/menus/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ List<MenuItem> items = [
new MenuItem<int>(
id: 0,
title: 'THE PADDOCK',
icon: Icons.fastfood,
prefix: Icon(Icons.fastfood),
),
new MenuItem<int>(
id: 1,
title: 'THE HERO',
icon: Icons.person,
prefix: Icon(Icons.person),
),
new MenuItem<int>(
id: 2,
title: 'HELP US GROW',
icon: Icons.terrain,
prefix: Icon(Icons.terrain),
),
new MenuItem<int>(
id: 3,
title: 'SETTINGS',
icon: Icons.settings,
prefix: Icon(Icons.settings),
),
];
final menu = Menu(
items: items.map((e) => e.copyWith(icon: null)).toList(),
items: items.map((e) => e.copyWith(prefix: null)).toList(),
);

final menuWithIcon = Menu(
Expand Down
46 changes: 41 additions & 5 deletions lib/menu_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ class _SideDrawerState extends State<SideDrawer> with TickerProviderStateMixin {
title: item.title,
isSelected: isSelected,
selectorColor: selectorColor,
textStyle: textStyle,
textStyle: item.textStyle ?? textStyle,
menuView: widget,
width: maxSlideAmount,
icon: item.icon == null ? null : Icon(item.icon),
icon: item.icon == null ? item.prefix : Icon(item.icon),
suffix: item.suffix,
onTap: onTap as dynamic Function()?,
drawBorder: !widget.animation,
)
Expand Down Expand Up @@ -547,6 +548,7 @@ class _MenuListItem extends StatelessWidget {
final TextStyle? textStyle;
final SideDrawer? menuView;
final Widget? icon;
final Widget? suffix;
final Direction direction;
final double? width;
final EdgeInsets? padding;
Expand All @@ -563,6 +565,7 @@ class _MenuListItem extends StatelessWidget {
this.direction = Direction.right,
this.width,
this.padding,
this.suffix,
});

@override
Expand All @@ -588,18 +591,25 @@ class _MenuListItem extends StatelessWidget {
flex: 1,
),
);
if (suffix != null)
children.add(Padding(
padding: EdgeInsets.only(right: 12),
child: IconTheme(
data: IconThemeData(color: _textStyle.color), child: suffix!),
));
return InkWell(
splashColor: const Color(0x44000000),
onTap: isSelected! ? null : onTap,
child: Container(
width: width,
alignment: Alignment.centerRight,
// padding: padding,
decoration: drawBorder!
? ShapeDecoration(
shape: Border(
left: BorderSide(
color: isSelected! ? selectorColor! : Colors.transparent,
color: isSelected == true
? selectorColor!
: Colors.transparent,
width: 5.0),
),
)
Expand Down Expand Up @@ -627,23 +637,49 @@ class Menu {
class MenuItem<T> {
final T? id;
final String title;

/// set icon from [MenuItem], if the icon is not null, the prefix must be null
final IconData? icon;

/// set prefix widget from [MenuItem], if the prefix is not null, the icon must be null
final Widget? prefix;

/// set prefix widget from [MenuItem]
final Widget? suffix;

/// set independent text style for title
final TextStyle? textStyle;

/// append data with [MenuItem], then can be use on itemBuilder
final dynamic data;

MenuItem({
this.id,
required this.title,
this.icon,
});
this.prefix,
this.suffix,
this.textStyle,
this.data,
}) : assert(prefix == null || icon == null);

MenuItem<T> copyWith({
T? id,
String? title,
IconData? icon,
Widget? prefix,
Widget? suffix,
TextStyle? textStyle,
dynamic? data,
}) {
return MenuItem<T>(
id: id ?? this.id,
title: title ?? this.title,
icon: icon,
prefix: prefix,
suffix: suffix,
textStyle: textStyle ?? this.textStyle,
data: data ?? this.data,
);
}
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: drawerbehavior
description: Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide..
version: 2.0.0+4
version: 2.1.0
# author: Shiburagi <tr32010@gmail.com>
homepage: https://github.com/shiburagi/Drawer-Behavior-Flutter

environment:
sdk: '>=2.12.0-259.9.beta <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down

0 comments on commit d8c5f7f

Please sign in to comment.