it_navigates 1.0.0
it_navigates: ^1.0.0 copied to clipboard
A powerful, elegant Flutter navigation package with state management, guards, animations, and comprehensive routing utilities. Makes navigation across mobile and web apps effortless!
it_navigates ๐งญ #
A powerful, elegant Flutter navigation package with state management, guards, animations, and comprehensive routing utilities. Makes navigation across mobile and web apps effortless! ๐
โจ Features #
- ๐ฏ State-aware Navigation - Built-in BLoC pattern for navigation state management
- ๐ Guest Mode Protection - Automatic handling of unauthenticated user navigation attempts
- ๐จ Custom Transitions - Beautiful fade, slide, scale, and rotation animations
- ๐ Extension Methods - Convenient shortcuts for common navigation patterns
- ๐ฑ Context Extensions - Easy-to-use extensions on
BuildContext - ๐ญ Pre-built Dialogs - Ready-to-use success, error, loading, and choice dialogs
- ๐ก๏ธ Type-safe - Fully typed navigation methods
- ๐ Well Documented - Comprehensive documentation and examples
- ๐งช Tested - Production-ready and thoroughly tested
๐ฆ Installation #
Add this to your package's pubspec.yaml file:
dependencies:
it_navigates: ^1.0.0
Then run:
flutter pub get
๐ Quick Start #
Basic Setup #
- Initialize the package in your
main()function:
import 'package:it_navigates/it_navigates.dart';
void main() {
// Optional: Configure the package
initNavigation(
primaryColor: Colors.purple,
guestMode: false,
splash: () => MySplashScreen(),
auth: () => isLoggedIn ? HomePage() : LoginPage(),
);
runApp(MyApp());
}
- Wrap your app with
BlocProvider:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => NavigationCubit(),
child: MaterialApp(
home: HomePage(),
),
);
}
}
Simple Navigation #
Use the convenient context extensions:
// Push a new page
context.push(ProfilePage());
// Push with replacement
context.pushReplacement(LoginPage());
// Push and remove all previous routes
context.pushAndRemoveUntil(HomePage());
// Pop current page
context.pop();
// Pop with result
context.pop("some result");
Navigation with Custom Transitions #
// Fade transition
context.fadeTransition(DetailsPage());
// Slide transition
context.slideTransition(SettingsPage());
// Scale transition
context.scaleTransition(AboutPage());
// Rotation transition
context.rotationTransition(InfoPage());
Named Routes #
// Navigate to named route
context.pushNamed('/profile', arguments: userId);
// Replace with named route
context.pushReplacementNamed('/home');
// Push named and remove all
context.pushNamedAndRemoveUntil('/login');
Show Dialogs #
// Choice dialog
await showChoiceDialog(
context: context,
title: 'Delete Item',
content: 'Are you sure you want to delete this item?',
onYes: () {
// Handle yes
},
onNo: () {
// Handle no
},
);
// Loading dialog
showLoadingDialog(context, message: 'Processing...');
// Success dialog
await showSuccessDialog(
context,
title: 'Success!',
message: 'Your changes have been saved.',
);
// Error dialog
await showErrorDialog(
context,
title: 'Error',
message: 'Something went wrong.',
);
Show SnackBars and Bottom Sheets #
// Show snackbar
context.showSnackBar('Item added to cart!');
// Show bottom sheet
context.showBottomSheet(
MyBottomSheetWidget(),
backgroundColor: Colors.white,
);
// Show dialog widget
context.showDialogWidget(MyCustomDialog());
๐ฏ Advanced Usage #
Using NavigationCubit #
For more complex navigation with state management:
final navCubit = NavigationCubit.get(context);
// Navigate with guest mode check
await navCubit.navigate(context, ProfilePage());
// Replace current page
await navCubit.navigateReplaced(context, HomePage());
// Navigate and clear stack
await navCubit.navigateOff(context, LoginPage());
// Navigate to home
await navCubit.navigateToHome(context);
// Pop current route
navCubit.pop(context);
Guest Mode Protection #
Enable guest mode to protect certain routes:
// Enable guest mode
isGuestMode = true;
// When user tries to navigate, they'll see a sign-in prompt
await navCubit.navigate(context, ProtectedPage());
// Shows: "Sign in required! Please sign in to continue"
Navigation State Management #
Listen to navigation state changes:
BlocBuilder<NavigationCubit, NavigationState>(
builder: (context, state) {
if (state is PagePushed) {
print('Navigated to: ${state.pageName}');
} else if (state is PagePopped) {
print('Popped from: ${state.pageName}');
}
return Container();
},
)
Custom Callbacks #
final navigate = Navigate(
preNavigationCallback: () {
print('About to navigate...');
// Perform analytics, logging, etc.
},
postNavigationCallback: () {
print('Navigation completed!');
// Clean up, update state, etc.
},
);
navigate.init(isGuestMode: false);
๐ฑ Platform Support #
| Platform | Supported |
|---|---|
| iOS | โ |
| Android | โ |
| Web | โ |
| macOS | โ |
| Windows | โ |
| Linux | โ |
๐ API Reference #
Extension Methods #
NavigationExtension
push<T>(Widget page)- Navigate to a new pagepushRoute<T>(Route<T> route)- Navigate with a custom routepushReplacement<T, TO>(Widget page)- Replace current pagepushAndRemoveUntil<T>(Widget page)- Push and clear stackpop<T>([T? result])- Pop current pagecanPop()- Check if can poppopUntil(predicate)- Pop until conditionpushNamed<T>(String routeName)- Navigate to named routepushReplacementNamed<T, TO>(String routeName)- Replace with named routepushNamedAndRemoveUntil<T>(String routeName)- Push named and clear stackshowBottomSheet<T>(Widget child)- Show modal bottom sheetshowDialogWidget<T>(Widget child)- Show dialogshowSnackBar(String message)- Show snackbarhideSnackBar()- Hide snackbar
CustomTransitionExtension
fadeTransition<T>(Widget page)- Fade transitionslideTransition<T>(Widget page)- Slide transitionscaleTransition<T>(Widget page)- Scale transitionrotationTransition<T>(Widget page)- Rotation transition
Components #
showChoiceDialog()- Customizable choice dialogshowLoadingDialog()- Loading indicator dialogshowSuccessDialog()- Success message dialogshowErrorDialog()- Error message dialog
NavigationCubit Methods #
navigate(context, widget)- Navigate with guest mode checknavigateReplaced(context, widget)- Replace current routenavigateOff(context, widget)- Navigate and clear stacknavigateToHome(context)- Navigate to homenavigateToSliderLogout(context)- Navigate to splash/logoutpop(context)- Pop current route
Global Configuration #
initNavigation()- Initialize package with custom settingsisGuestMode- Toggle guest modeappColor- Set primary colorsplashScreen- Configure splash screenauthRouter- Configure auth routing
๐ค Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author #
Saif Almajd (@syf-almjd)
๐ Show Your Support #
Give a โญ๏ธ if this project helped you!
๐ Changelog #
See CHANGELOG.md for a list of changes.
๐ Issues #
Please file issues here.