ap_drawer 0.1.0
ap_drawer: ^0.1.0 copied to clipboard
Animated side drawer for Flutter with 14 transitions, a ready-made app shell, theming, RTL layouts and web support.
ap_drawer #
An animated side drawer for Flutter with 14 transitions, a ready-made app shell (top bar, animated bottom bar, language button, profile header, footer), full theming, right-to-left layouts and a responsive web experience.
Created and maintained by Ankit (@Ankit342).
▶ Live demo — open it, tap the menu button and try every transition on the Menu styles page.
Contents #
- Features
- Requirements
- Installation
- Quick start
- Transitions
- Building blocks
- Using ApDrawerShell
- Using ApDrawer directly
- Menu items and expandable groups
- Letting users choose the transition
- Theming and white-labelling
- Safe areas
- Responsive layouts and the web
- Right-to-left and languages
- Controlling the drawer from code
- Important notes
- Example app
- API overview
- Credits
- License
Features #
Transitions
- Fourteen drawer transitions, from a classic overlay to 3D cube, frosted glass, liquid and folding menus.
- Page-moving styles and overlay styles where the page stays still.
- Change the transition at runtime and persist the user's choice.
- Animated previews of every transition, plus a ready-made picker widget.
Ready-made app shell
ApScaffold— one widget with a top bar, body, bottom bar and drawer.ApDrawerShell— add the drawer to any page you already have.- Animated top bar with logo area, actions, notification badge and a menu button that morphs into a close icon.
- Animated curved bottom bar that becomes a floating dock on wide screens.
- Language button with a menu of languages (full or compact form).
- Profile header, section captions, log-out footer and a painted logo.
- Expandable menu groups, selected-item highlighting and menu icons.
Customisation
ApDrawerTheme— colours, fonts and radii in one object, with a dark variant and automatic contrast for icons and text.ApSafeArea— decide which screen insets the menu keeps clear.- Left/right (start/end) drawer, drawer width, animation duration and curves, edge dragging, tap-to-close, pinned header and footer.
Platform
- Responsive layouts for phones, tablets and large browser windows.
Esccloses the drawer, and mouse dragging works on desktop and web.- Right-to-left layouts.
- Semantic labels for screen readers.
Requirements #
- Flutter 3.47 or newer (Dart 3.13 or newer).
- The package is built on the new
material_uilibrary, so importpackage:material_ui/material_ui.dartin your app, as recent Flutter versions recommend.
Installation #
dependencies:
ap_drawer: ^0.1.0
material_ui: ^1.11.1
import 'package:ap_drawer/ap_drawer.dart';
import 'package:material_ui/material_ui.dart';
Quick start #
ApScaffold gives you a complete screen with a drawer in a few lines:
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return ApScaffold(
logo: const ApLogo(),
style: ApDrawerStyle.cube,
navItems: <ApNavItem>[
ApNavItem(
id: 'home',
title: 'Home',
icon: Icons.home_rounded,
onTap: () => Navigator.pushNamed(context, '/home'),
),
ApNavItem(
id: 'settings',
title: 'Settings',
icon: Icons.settings_outlined,
onTap: () => Navigator.pushNamed(context, '/settings'),
),
],
selectedNavId: 'home',
drawerHeader: const ApProfileHeader(
name: 'Alex Morgan',
subtitle: 'alex@example.com',
),
drawerFooter: ApDrawerFooter(
onLogout: () {},
versionText: 'Version 1.0.0',
),
body: const Center(child: Text('Hello, drawer!')),
);
}
}
The menu button in the top bar opens the drawer. Tapping a menu item closes
the drawer first and then calls its onTap.
Transitions #
Set one with style: (for example ApDrawerStyle.liquid).
| Style | Kind | What it does |
|---|---|---|
slide |
Moves the page | The page glides aside and shrinks slightly. |
tilt |
Moves the page | The page leans back in perspective. |
cube |
Moves the page | Page and menu turn like two faces of a cube, sharing one edge. |
door |
Moves the page | The page swings open on a hinge. |
float |
Moves the page | The page drifts away as a tilted card. |
parallax |
Moves the page | The page pushes aside and casts a shadow while the menu glides in behind it more slowly. |
stack |
Moves the page | The page becomes a card on top of a deck of stacked cards. |
pivot |
Moves the page | The page swings away around its bottom corner. |
fold |
Moves the page | The menu folds open like a sheet of paper, its crease receding in perspective, while the page is pushed aside. The color behind the folds shows through the notches. |
glass |
Overlay | A frosted-glass panel blurs what is behind it and floats inset from the screen edges. |
liquid |
Overlay | The menu flows in with a liquid edge that settles flat. |
reveal |
Overlay | The menu blooms open in a circle from the corner. |
wipe |
Overlay | The menu is revealed by a diagonal mask that sweeps across it. |
none |
Overlay | A plain side panel over a dimmed page, with no page animation. |
Overlay styles keep the page where it is and lay the menu on top. Each style
also exposes a label, a description, a recommendedMinScale and an
isOverlay flag through the ApDrawerStyleInfo extension.
Building blocks #
Everything is exported from package:ap_drawer/ap_drawer.dart.
| Widget | Purpose |
|---|---|
ApScaffold |
Complete page: top bar, body, bottom bar and drawer. |
ApDrawerShell |
Wraps any page in the drawer and builds the menu from ApNavItems. |
ApDrawer |
The low-level drawer widget for full control. |
ApTopBar / ApShellTopBar |
App bar with logo, actions and the menu button. The shell version connects to the drawer by itself. |
ApTopBarAction |
Square icon button with an optional unread badge (badgeCount). |
ApMenuButton |
Menu button that morphs into a close icon. |
ApLanguageButton |
Language chooser with a popup menu; compact for narrow screens. |
ApBottomBar |
Animated curved bottom navigation bar. |
ApNavTile / ApExpandableNavTile |
Menu rows, plain or expandable. |
ApProfileHeader |
User card with a network avatar and an initials fallback. |
ApDrawerFooter |
Card with a log-out button and a version line. |
ApSectionTitle |
Small caption with an accent bar. |
ApLogo |
Painted logo mark with a wordmark, themed by your brand colours. |
ApDrawerStylePicker |
Grid of animated previews that lets users choose a transition. |
ApDrawerStylePreview |
A single looping miniature of a transition. |
Using ApDrawerShell #
Already have a Scaffold? Wrap it in ApDrawerShell:
ApDrawerShell(
items: navItems,
style: ApDrawerStyle.parallax,
header: const ApProfileHeader(name: 'Alex Morgan'),
footer: ApDrawerFooter(onLogout: signOut),
sectionTitle: 'Navigation',
selectedId: 'home',
content: Scaffold(
appBar: const ApShellTopBar(logo: ApLogo()),
body: const MyPage(),
),
);
ApShellTopBar finds the shell automatically, so its menu button opens and
closes the drawer and shows the right icon.
Useful ApDrawerShell options: direction, maxDrawerWidth,
animationDuration, dragEnabled, menuSafeArea, theme,
styleController and onDrawerChanged.
Using ApDrawer directly #
For full control, use ApDrawer with an ApDrawerController. The drawer
swaps page widgets; it does not push Navigator routes.
final controller = ApDrawerController(
initialPage: const HomePage(),
items: <ApDrawerItem>[
ApDrawerItem.withPage(
alias: 'home',
icon: const Icon(Icons.home),
text: const Text('Home'),
page: const HomePage(),
),
ApDrawerItem.withPage(
alias: 'settings',
icon: const Icon(Icons.settings),
text: const Text('Settings'),
page: const SettingsPage(),
),
],
);
Widget build(BuildContext context) {
return Scaffold(
body: ApDrawer(
controller: controller,
style: ApDrawerStyle.glass,
direction: ApDrawerDirection.end,
),
);
}
Open or close the nearest drawer from any descendant:
ApDrawer.of(context)?.toggle();
The controller can also change items and pages at runtime: addItem,
removeItem, clearItems, refreshItems, selectItem(alias),
replacePage, and optional page history with maintainPageHistory,
canGoBack, goBack and clearHistory.
You can also use ApDrawer with plain content: and no controller when
your app handles navigation elsewhere.
Other ApDrawer options: drawerWidth, minScale, borderRadius,
shadowColor, shadowOffset, disableContentTap, dragEnabled,
edgeDragWidth, animationDuration, slideCurve, scaleCurve,
animateItems, perspective, contentColor, decoration, header,
footer, headerPinned, footerPinned, scrollable,
centerScrollableItems, menuPadding, semanticLabel and
onDrawerChanged.
Menu items and expandable groups #
ApNavItem is plain data, so the package never depends on your router or
state management:
ApNavItem(
id: 'services',
title: 'Services',
icon: Icons.account_balance_rounded,
children: <ApNavChild>[
ApNavChild(title: 'Federal', onTap: () {}),
ApNavChild(title: 'Civilian', onTap: () {}),
],
);
An item with children becomes an expandable group (one open at a time, and
collapsed again when the drawer closes). Use leading for a custom icon
widget such as an image or SVG, and trailing to replace the chevron.
Letting users choose the transition #
final styles = ApDrawerStyleController(
initial: ApDrawerStyle.slide,
onChanged: (style) => save(style.name), // persist it any way you like
);
// Restore a saved value at startup, without triggering onChanged.
styles.restore(savedName);
// Use it in the scaffold or shell…
ApScaffold(styleController: styles, /* … */);
// …and let people pick with live previews.
ApDrawerStylePicker(controller: styles);
Changing the controller re-animates the drawer in the new style
immediately. ApDrawerStyleController.parse(name) turns a stored string back
into a style.
Theming and white-labelling #
ApDrawerThemeScope(
theme: const ApDrawerTheme(
primaryColor: Color(0xFF0F5132),
accentColor: Color(0xFFE9B949),
highlightColor: Color(0xFF2E9E6B),
fontFamily: 'Poppins',
),
child: MyApp(),
);
ApDrawerTheme()works with no arguments;ApDrawerTheme.dark()is a dark variant;copyWithtweaks any field.- Controls colours,
fontFamily/fontPackage, and the radii of tiles, panels and the page. onPrimaryColorpicks a readable colour on top of your primary colour, so icons and text stay legible in light and dark themes.- Pass
theme:directly toApScaffoldorApDrawerShell, or provide it once withApDrawerThemeScope.
Safe areas #
ApSafeArea decides which screen insets (notch, status bar, home indicator,
rounded corners) the menu keeps clear:
ApScaffold(
menuSafeArea: const ApSafeArea.all(), // all four sides
// menuSafeArea: const ApSafeArea.none(), // edge to edge
// menuSafeArea: const ApSafeArea(left: true), // pick sides
// menuSafeArea: const ApSafeArea(
// minimum: EdgeInsets.symmetric(vertical: 32), // extra breathing room
// ),
// …
);
The default, ApSafeArea.standard, keeps the top and bottom insets clear and
adds at least 16 px of margin above and below the menu.
Responsive layouts and the web #
- Top bar: content is centered up to
topBarMaxWidth; match it to your page width so the bar and the page line up.ApLanguageButton(compact: true)saves space on narrow screens. - Bottom bar: attached to the bottom edge on phones and tablets, and a
floating, centered dock with rounded corners from
floatingBreakpoint(900 px by default). Tune it withmaxWidth,cornerRadiusandfloatingMargin. - Desktop and web: the menu width is capped by
maxDrawerWidth,Esccloses the drawer, and mouse dragging works. - The example app shows a full responsive setup.
Right-to-left and languages #
direction: ApDrawerDirection.start follows the ambient text direction (left
in LTR, right in RTL). Use ApDrawerDirection.end for the opposite side.
Menu rows, borders and spacing use directional geometry, so layouts mirror
correctly.
ApLanguage describes a language entry (code, name, flag, region)
and includes ready-made english, spanish, french and arabic values.
ApLanguageButton reports the chosen code, and you decide how to localise
your app.
Controlling the drawer from code #
final shell = ApDrawerShell.of(context); // or maybeOf(context)
shell.openDrawer();
shell.toggleDrawer();
await shell.closeDrawer();
shell.isDrawerOpen; // current state
shell.isOpenNotifier; // ValueNotifier<bool> to listen to
Important notes #
- Fold and
GlobalKeys. While it animates, thefoldstyle draws the menu in two halves, so avoidGlobalKeys inside menu items when you use it. Once the drawer is fully open a single copy is shown. The color visible in the notches isApDrawer.backdropColor(the shell uses your theme's accent color). ApBottomBarandmaterial_ui. The bottom bar is built on thecurved_navigation_bar_propackage. If your app runs onmaterial_uiand the bar reports missing theme or localization data, wrap your app inMaterialUiCompatibilityBridge. Put anyDirectionalityinside the bridge, because the bridge installs its ownLocalizations.- Both packages need Flutter 3.47 or newer.
Example app #
A full showcase with mock data and network images lives in example/:
cd example
flutter pub get
flutter run -d chrome
It shows every transition, the style picker, four languages (including Arabic for RTL), three brand palettes, a dark theme, the animated bottom bar and a layout that adapts from phone to desktop.
API overview #
| Area | Main types |
|---|---|
| Drawer core | ApDrawer, ApDrawerController, ApDrawerItem, ApDrawerControl, ApDrawerDirection |
| Transitions | ApDrawerStyle, ApDrawerStyleController, ApDrawerStyleInfo, ApDrawerStylePicker, ApDrawerStylePreview |
| App shell | ApScaffold, ApDrawerShell, ApShellTopBar |
| Menu data | ApNavItem, ApNavChild, ApExpandableState, ApSafeArea |
| Widgets | ApTopBar, ApTopBarAction, ApMenuButton, ApBottomBar, ApBottomBarItem, ApLanguageButton, ApLanguage, ApNavTile, ApExpandableNavTile, ApNavIconBox, ApProfileHeader, ApDrawerFooter, ApSectionTitle, ApLogo |
| Theming | ApDrawerTheme, ApDrawerThemeScope |
Credits #
ap_drawer is created and maintained by Ankit
(@Ankit342).
The animated bottom bar uses the
curved_navigation_bar_pro
package.
Bug reports and feature requests are welcome in the issue tracker.
License #
Released under the MIT License.