uloc 0.0.1 copy "uloc: ^0.0.1" to clipboard
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 provider for easy state and logic injection
  • πŸ” Auto-generates Routes and ULoC map 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

4
likes
160
points
86
downloads

Publisher

verified publisherdannynguyen.vn

Weekly Downloads

A lifecycle-aware routing library for Flutter. Supports named routes, Provider integration, code generation, and page lifecycle hooks like onInit, onReady, and onDispose.

Homepage
Repository (GitHub)
View/report issues

Topics

#routing #codegen #flutter #provider #architecture

Documentation

API reference

License

MIT (license)

Dependencies

flutter, meta, provider

More

Packages that depend on uloc