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

outdated

Simple Router for Pages, Dialogs, Loading tasks. Powerful functions, interfaces will support your app.

example/main.dart

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

final router = UiRouter(
  pages: {
    '/a': (params) => PageA(),
    '/b': (params) => PageB(),
    '/c/:msg': (params) => PageC(params['msg']!),
  },
  dialogs: {
    '/x': (call) => DialogX(call),
  },
);

void main() {
  final widget = UiRouterWidget(router);
  final app = MaterialApp(home: widget);
  runApp(app);
}

//
//  Page A
//
class PageA extends StatelessWidget {
  push() {
    router.push('/b');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Page A')),
      body: ElevatedButton(onPressed: push, child: Text('Push To B')),
    );
  }
}

//
//  Page B
//
class PageB extends StatelessWidget {
  push() {
    router.push('/c/Hello');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Page B')),
      body: ElevatedButton(
          onPressed: push, child: Text('Push to C with a message')),
    );
  }
}

//
//  Page C
//
class PageC extends StatelessWidget {
  final String message;
  PageC(this.message);

  openDialog() {
    final call = router.open('/x');

    call.onEvent((value) {
      debugPrint(value);

      router.close();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Page C')),
      body: ElevatedButton(
          onPressed: openDialog, child: Text('Received: $message')),
    );
  }
}

//
//  Dialog X
//
class DialogX extends StatelessWidget {
  final UiCall call;
  DialogX(this.call);

  event() {
    call.event('Event from Dialog X');
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      width: 300,
      height: 400,
      padding: const EdgeInsets.all(50),
      child: SizedBox(
        width: 200,
        height: 200,
        child: ElevatedButton(
          onPressed: event,
          child: Text('OK'),
        ),
      ),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisherflut.rbdog.biz

Simple Router for Pages, Dialogs, Loading tasks. Powerful functions, interfaces will support your app.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ui_router