sailor 0.0.2 copy "sailor: ^0.0.2" to clipboard
sailor: ^0.0.2 copied to clipboard

outdated

Easily manage page navigation in Flutter apps. Add page transition animations, log navigation events.

example/lib/main.dart

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

void main() async {
  Routes.createRoutes();
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Compass Example',
      home: Home(),
      onGenerateRoute: Routes.sailor.generator(),
      navigatorObservers: [
        SailorLoggingObserver(),
      ],
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Compass Example'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open New Page'),
          onPressed: () async {
            final response = await Routes.sailor.navigate<bool>(
              context,
              "/secondPage",
              args: SecondPageArgs('Hey there'),
            );

            print("Response from SecondPage: $response");
          },
        ),
      ),
    );
  }
}

class SecondPageArgs extends BaseArguments {
  final String text;

  SecondPageArgs(this.text) : assert(text != null);
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final args = Sailor.arguments<SecondPageArgs>(context);

    return Scaffold(
      appBar: AppBar(
        title: Text('Compass Example'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text(args?.text ?? 'Second Page'),
            RaisedButton(
              child: Text('Close Page'),
              onPressed: () {
                Navigator.of(context).pop(true);
              },
            ),
          ],
        ),
      ),
    );
  }
}

class Routes {
  static final sailor = Sailor();

  static void createRoutes() {
    sailor
      ..addRoute(SailorRoute(
        name: "/secondPage",
        builder: (context, args) {
          return SecondPage();
        },
      ));
  }
}
129
likes
0
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

Easily manage page navigation in Flutter apps. Add page transition animations, log navigation events.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on sailor