uloc 0.0.1
uloc: ^0.0.1 copied to clipboard
A lifecycle-aware routing library for Flutter. Supports named routes, Provider integration, code generation, and page lifecycle hooks like onInit, onReady, and onDispose.
π ULoC β UI-Logic-Controller / Router for Flutter #
ULoC is a developer-friendly tool that combines routing, logic injection, and screen scaffolding into one seamless workflow for Flutter.
It's designed to work perfectly with Provider, and follows scalable patterns like MVC or MVVM.
Stop wiring up routes manually. Let ULoC handle it, while you focus on logic and design.
π§ Overview #
- π§ Based on
providerfor easy state and logic injection - π Auto-generates
RoutesandULoCmap from a@ULoCDeclaration - π§± Scaffolds new screens with controller + view files
- 𧬠Lifecycle hooks (
onInit,onReady,onDispose) - π Supports dynamic named routes with parameters β great for deep linking
- β Perfect for large projects and scalable architecture (MVC/MVVM)
π¦ Installation #
In your Flutter project:
dependencies:
uloc: ^1.0.0
Then:
dart pub get
βοΈ CLI Commands #
π Generate Routes #
Auto-generates route constants and ULoC map:
dart run uloc gen
π Generate Routes from β to #
dart run uloc gen <source_file.dart> <destination_file.dart>
π§± Scaffold a New Screen #
Creates YourScreen and YourScreenController:
dart run uloc new <WidgetName> <Directory>
Example:
dart run uloc new home_page lib/screens/
Creates:
lib/screens/home/
βββ views/pages/home_page.dart
βββ controllers/home_controller.dart
β¨ Route Declaration Example #
@ULoCDeclaration()
class MyRoutes extends ULoCRouteDeclaration {
@override
Map<String, ULoCRoute<ULoCProvider>> get route => {
'HOME': ULoCRoute(
route: '/',
provider: (context, _) => HomeController(context),
child: Home,
),
'DETAIL': ULoCRoute(
route: '/detail/:id/:name',
provider: (context, params) =>
DetailController(context, params?['id'], params?['name']),
child: Detail,
),
};
}
π Generated Output #
class Routes {
static const RouteName HOME = '/';
static RouteName DETAIL({String? id, String? name}) =>
(id == null || name == null)
? '/detail/:id/:name'
: '/detail/$id/$name';
}
final ULoC uloc = ULoC([
RouteProperties(
routeName: Routes.HOME,
provider: (context, _) => HomeController(context),
child: Home(),
),
RouteProperties(
routeName: Routes.DETAIL(),
provider: (context, params) =>
DetailController(context, params?['id'], params?['name']),
child: Detail(),
),
]);
--
π Usage #
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ULoC Demo',
initialRoute: Routes.HOME,
routes: uloc.routes,
onGenerateRoute: uloc.routeBuilder,
);
}
}
π Lifecycle Hooks #
Each controller can optionally define lifecycle methods:
@override
void onInit() {
fetchData();
}
@override
void onReady() {
showDialog();
accessContext();
}
@override
void onDispose() {
removeResource()
}
π§ Architecture Friendly #
ULoC fits into modern app structure:
- MVC β Controller handles logic, View is UI
- MVVM β Controller = ViewModel, View observes data changes
- Clean separation between logic and UI
π Deep Linking #
Named routes support :params like /user/:id. Navigate with:
context.pushNamed(Routes.Detail(id: '42'))
Works with Firebase Dynamic Links, URI parsers, etc.
β€οΈ Contributing #
Feel free to:
- Submit bug reports or ideas
- Open pull requests
- Improve the ecosystem
π License #
MIT License Β© NGUYEN HAI DANG