ui_router 3.0.0 copy "ui_router: ^3.0.0" to clipboard
ui_router: ^3.0.0 copied to clipboard

GoRouter Alternative, without context

bitbnn-app-header

Now under development #

  • Pages, Dialogs, Tabs, Loading
  • powerful widgets

https://pub.dev/packages/ui_router

Use #

import 'package:flutter/material.dart';
import 'package:ui_router/ui_router.dart';

void main() {
  final view = UiRouterView(router);
  final app = MaterialApp(home: view);
  runApp(app);
}

final router = UiRouter(
  pages: [
    UiPage(
      path: '/index',
      build: (state) => const MyIndexPage(),
    ),
    UiBase(
      path: '/base',
      build: (state, child) => MyBasePage(child: child),
      pages: [
        UiPage(
          path: '/sub-1',
          build: (state) => const MySub1Page(),
        ),
        UiPage(
          path: '/sub-2',
          build: (state) => const MySub2Page(),
        ),
      ],
    ),
  ],
);

//

//

//

// --- Your Pages ---

//

//

//

// Index
class MyIndexPage extends StatelessWidget {
  const MyIndexPage({super.key});

  @override
  Widget build(BuildContext context) {
    final buttons = [
      //
      // Button
      //
      ElevatedButton(
        onPressed: () {
          router.push('/base/sub-1');
        },
        child: const Text('Push To Sub1'),
      ),
    ];

    return Scaffold(
      appBar: AppBar(title: const Text('Index')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: buttons,
        ),
      ),
    );
  }
}

// Base
class MyBasePage extends StatelessWidget {
  const MyBasePage({
    super.key,
    required this.child,
  });

  final Widget child;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.orange,
      appBar: AppBar(title: const Text('Base')),
      body: Center(
        child: SizedBox(
          width: 300,
          height: 500,
          child: child,
        ),
      ),
    );
  }
}

// Sub1
class MySub1Page extends StatelessWidget {
  const MySub1Page({super.key});

  @override
  Widget build(BuildContext context) {
    final buttons = [
      //
      // Button
      //
      ElevatedButton(
        onPressed: () {
          router.base('/base').push('/sub-2');
        },
        child: const Text('Push To Sub2'),
      ),
    ];

    return Scaffold(
      appBar: AppBar(title: const Text('Sub 1')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: buttons,
        ),
      ),
    );
  }
}

// Sub2
class MySub2Page extends StatelessWidget {
  const MySub2Page({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sub 2')),
    );
  }
}

🎉 Contributions, issues are welcomed!

0
likes
0
pub points
0%
popularity

Publisher

verified publisherflut.rbdog.biz

GoRouter Alternative, without context

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ui_router