Flutter ShadcnUI
repository·main·Indexed 25 days ago
https://github.com/nank1ro/flutter-shadcn-uiA library of highly customizable UI components for Flutter inspired by the Shadcn UI design system. It provides a collection of high-quality widgets—including ShadButton, ShadAccordion, ShadCalendar, and ShadAvatar—designed for simplicity and deep customization. The library includes a CLI for installing specific components directly into project source code to allow full ownership of the implementation.
What's inside flutter-shadcn-ui
- Flutter ShadcnUI is a port of Shadcn UI for Flutter, providing a collection of awesome, fully customizable UI components. It aims to provide high-quality widgets designed with simplicity and extreme customizability in mind.
Use the ShadAccordion component
mainThe
ShadAccordionis a vertically stacked set of interactive headings that reveal content sections. It follows the WAI-ARIA design pattern and includes default animations and styling.By default,
ShadAccordionallows only one item to be expanded at a time. To allow multiple items to be expanded simultaneously, use the.multiple()constructor.Use the Breadcrumb component
mainThe
ShadBreadcrumbcomponent displays the path to the current resource using a hierarchy of links. It accepts a list ofchildrenwhich can includeShadBreadcrumbLinkfor clickable navigation,ShadBreadcrumbDropdownfor collapsed menus, or standard widgets likeTextfor the current page label.class PrimaryBreadcrumb extends StatelessWidget { const PrimaryBreadcrumb({super.key}); @override Widget build(BuildContext context) { return ShadBreadcrumb( children: [ ShadBreadcrumbLink( onPressed: () => print('Navigating to Home'), child: const Text('Home'), ), ShadBreadcrumbDropdown( items: [ ShadBreadcrumbDropMenuItem( onPressed: () => print('Navigating to Documentation'), child: const Text('Documentation'), ), ShadBreadcrumbDropMenuItem( onPressed: () => print('Navigating to Themes'), child: const Text('Themes'), ), ShadBreadcrumbDropMenuItem( onPressed: () => print('Navigating to Github'), child: const Text('Github'), ), ], showDropdownArrow: false, child: ShadBreadcrumbEllipsis(), ), Text('Components'), Text('Breadcrumb'), ], ); } }Use the ShadTooltip component
mainThe
ShadTooltipcomponent displays a popup containing information related to an element when the element receives keyboard focus or mouse hover.To implement a tooltip, wrap your target widget with
ShadTooltipand provide abuilderfunction that returns the content to be displayed. Thechildparameter should be the widget that triggers the tooltip.Important Requirement: For hover functionality to work, the
childwidget must implementShadGestureDetector. Standard widgets likeShadButtonalready implement this, but if you are using a plain widget (like anImage), you must wrap it in aShadGestureDetectorto enable hover triggers.ShadTooltip( builder: (context) => const Text('Add to library'), child: ShadButton.outline( child: const Text('Hover/Focus'), onPressed: () {}, ), ),Use Google Fonts with Shadcn UI
mainTo use Google Fonts, install the
google_fontspackage and use theShadTextTheme.fromGoogleFontconstructor in yourShadAppconfiguration.return ShadApp( theme: ShadThemeData( brightness: Brightness.light, colorScheme: const ShadZincColorScheme.light(), textTheme: ShadTextTheme.fromGoogleFont(GoogleFonts.poppins), ), );Configure the app theme and color scheme
mainUse
ShadAppto define the application's theme. You can specifythemeanddarkThemeusingShadThemeData. EachShadThemeDatarequires abrightnessand acolorScheme.Supported color scheme names include:
blue,gray,green,neutral,orange,red,rose,slate,stone,violet,yellow, andzinc.@override Widget build(BuildContext context) { return ShadApp( darkTheme: ShadThemeData( brightness: Brightness.dark, colorScheme: const ShadSlateColorScheme.dark(), ), child: ... ); }Use ShadIconButton for icon buttons
mainThe
ShadIconButtoncomponent displays a button containing an icon. It supports several visual styles through different constructors or properties, including primary, secondary, destructive, outline, and ghost styles.ShadIconButton( onPressed: () => print('Primary'), icon: const Icon(LucideIcons.rocket), )Use the ShadBadge component
mainThe
ShadBadgecomponent displays a badge or a component that looks like a badge. It provides several constructors to achieve different visual styles:Primary(default),Secondary,Destructive, andOutline.// Primary (Default) ShadBadge( child: const Text('Primary'), ) // Secondary ShadBadge.secondary( child: const Text('Secondary'), ) // Destructive ShadBadge.destructive( child: const Text('Destructive'), ) // Outline ShadBadge.outline( child: const Text('Outline'), )Use Shadcn with Cupertino components
mainTo use Shadcn components alongside Cupertino components, use
ShadApp.customwith anappBuilderthat returns aCupertinoApp. Include the necessary localization delegates. If using aRouter, useCupertinoApp.router.import 'package:shadcn_ui/shadcn_ui.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return ShadApp.custom( themeMode: ThemeMode.dark, darkTheme: ShadThemeData( brightness: Brightness.dark, colorScheme: const ShadSlateColorScheme.dark(), ), appBuilder: (context) { return CupertinoApp( theme: CupertinoTheme.of(context), localizationsDelegates: const [ GlobalShadLocalizations.delegate, DefaultMaterialLocalizations.delegate, DefaultCupertinoLocalizations.delegate, DefaultWidgetsLocalizations.delegate, ], builder: (context, child) { return ShadAppBuilder(child: child!); }, ); }, ); } }Implement a form with ShadForm
mainUse
ShadFormto manage form state, validation, and field values centrally. This eliminates the need to manage individual controllers for every field. To interact with the form, use aGlobalKey<ShadFormState>.Key benefits:
- Centralized state management.
- Access all values as a single
Map<String, dynamic>. - Automatic validation via
saveAndValidate().
final formKey = GlobalKey<ShadFormState>(); // In your build method ShadForm( key: formKey, child: Column( children: [ ShadInputFormField( id: 'username', label: const Text('Username'), validator: (v) { if (v.length < 2) return 'Username must be at least 2 characters.'; return null; }, ), ShadButton( child: const Text('Submit'), onPressed: () { if (formKey.currentState!.saveAndValidate()) { print('Success: ${formKey.currentState!.value}'); } }, ), ], ), )Configure Theme and Color Scheme in ShadApp
mainTo define the theme and color scheme for your application, use the
ShadThemeDataclass within thethemeordarkThemeproperties ofShadApp. You can specify thebrightnessand a specificcolorScheme(e.g.,ShadSlateColorScheme).You can override specific properties of a theme, such as individual color scheme properties (like
background) or component themes (likeprimaryButtonTheme).import 'package:shadcn_ui/shadcn_ui.dart'; @override Widget build(BuildContext context) { return ShadApp( darkTheme: ShadThemeData( brightness: Brightness.dark, colorScheme: const ShadSlateColorScheme.dark( background: Colors.blue, ), primaryButtonTheme: const ShadButtonTheme( backgroundColor: Colors.cyan, ), ), child: ... ); }Customize component animations with flutter_animate
mainShadcn UI components utilize theflutter_animatelibrary. Many components accept aList<Effect>parameter, allowing you to easily customize or add animations to the UI elements.