Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parameters to side_menu.dart #24

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:easy_sidemenu/easy_sidemenu.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
Expand Down Expand Up @@ -130,11 +130,24 @@ class _MyHomePageState extends State<MyHomePage> {
},
icon: const Icon(Icons.settings),
),
SideMenuItem(
priority: 5,
title: 'Only Title',
onTap: () {
page.jumpToPage(5);
},
),
SideMenuItem(
priority: 6,
onTap: () {
page.jumpToPage(6);
},
icon: const Icon(Icons.smart_button_sharp),
),
const SideMenuItem(
priority: 7,
title: 'Exit',
onTap: () async {},
icon: const Icon(Icons.exit_to_app),
icon: Icon(Icons.exit_to_app),
),
],
),
Expand Down Expand Up @@ -187,6 +200,24 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
),
Container(
color: Colors.white,
child: const Center(
child: Text(
'Only Title',
style: TextStyle(fontSize: 35),
),
),
),
Container(
color: Colors.white,
child: const Center(
child: Text(
'Only Icon',
style: TextStyle(fontSize: 35),
),
),
),
],
),
),
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion lib/src/side_menu.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:easy_sidemenu/src/global/global.dart';
import 'package:easy_sidemenu/src/side_menu_display_mode.dart';
import 'package:easy_sidemenu/src/side_menu_item.dart';
import 'package:easy_sidemenu/src/side_menu_style.dart';
import 'package:easy_sidemenu/src/side_menu_toggle.dart';
import 'package:flutter/material.dart';

import 'global/global.dart';

class SideMenu extends StatefulWidget {
/// Page controller to control [PageView] widget
final PageController controller;
Expand Down
34 changes: 19 additions & 15 deletions lib/src/side_menu_item.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import 'package:badges/badges.dart';
import 'package:easy_sidemenu/src/global/global.dart';
import 'package:easy_sidemenu/src/side_menu_display_mode.dart';

import 'package:flutter/material.dart';

import 'global/global.dart';

class SideMenuItem extends StatefulWidget {
/// #### Side Menu Item
///
/// This is a widget as [SideMenu] items with text and icon
const SideMenuItem({
Key? key,
required this.onTap,
required this.title,
required this.icon,
this.onTap,
this.title,
this.icon,
required this.priority,
this.badgeContent,
this.badgeColor,
this.tooltipContent,
}) : super(key: key);
}) : assert(title != null || icon != null,
'Title and icon should not be empty at the same time'),
super(key: key);

/// A function that call when tap on [SideMenuItem]
final Function onTap;
final Function? onTap;

/// Title text
final String title;
final String? title;

/// A Icon to display before [title]
final Icon icon;
final Icon? icon;

/// Priority of item to show on [SideMenu], lower value is displayed at the top
///
Expand Down Expand Up @@ -103,7 +105,8 @@ class _SideMenuItemState extends State<SideMenuItem> {
}

/// Set icon for of [SideMenuItem]
Widget _generateIcon(Icon mainIcon) {
Widget _generateIcon(Icon? mainIcon) {
if (mainIcon == null) return const SizedBox();
Icon icon = Icon(
mainIcon.icon,
color: widget.priority == currentPage.ceil()
Expand Down Expand Up @@ -140,8 +143,8 @@ class _SideMenuItemState extends State<SideMenuItem> {
valueListenable: Global.displayModeState,
builder: (context, value, child) {
return Tooltip(
message: (value == SideMenuDisplayMode.compact
&& Global.style.showTooltipOverItemsName)
message: (value == SideMenuDisplayMode.compact &&
Global.style.showTooltipOverItemsName)
? widget.tooltipContent ?? widget.title
: "",
child: Padding(
Expand All @@ -160,14 +163,15 @@ class _SideMenuItemState extends State<SideMenuItem> {
if (value == SideMenuDisplayMode.open)
Expanded(
child: Text(
widget.title,
widget.title ?? '',
style: widget.priority == currentPage.ceil()
? const TextStyle(
fontSize: 17, color: Colors.black)
.merge(Global.style.selectedTitleTextStyle)
: const TextStyle(
fontSize: 17, color: Colors.black54)
.merge(Global.style.unselectedTitleTextStyle),
.merge(
Global.style.unselectedTitleTextStyle),
),
),
],
Expand All @@ -178,7 +182,7 @@ class _SideMenuItemState extends State<SideMenuItem> {
),
),
),
onTap: () => widget.onTap(),
onTap: () => widget.onTap!(),
onHover: (value) {
setState(() {
isHovered = value;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/side_menu_toggle.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:easy_sidemenu/src/global/global.dart';
import 'package:easy_sidemenu/src/side_menu_display_mode.dart';
import 'package:flutter/material.dart';

import 'global/global.dart';

class SideMenuToggle extends StatefulWidget {
final Function? onTap;
const SideMenuToggle({
Expand Down