virgil 0.8.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new68

Virgil

A simple navigator assistant that allows for passing data to named routes

Setup

Import the package

  • Within

      dependencies:
        flutter:
    

    add

          virgil: 0.8.0
    
  • Run flutter packages get

Add it to your app

  • Inferno is a class containing your routes. It lives in the home: property of your *App widget.
  • To create Inferno, you need to give it routes
    • It's routes are very similar to the regular navigator's routes, with one exception
        {
            '/': (context, arguments) => PageOne(),
            '/hello': (context, arguments) => PageTwo(arguments),
        }
      
      It takes arguments with the context. You can pass the arguments to the widget.
  • To create it and start your app, you need to call .home(context, [initialRoute]) on it.
      MaterialApp(
          home: Inferno(
            {
              '/': (context, arguments) => PageOne(),
              '/hello': (context, arguments) => PageTwo(arguments),
            },
          ).home(context), // you can give an optional argument to provide an initial route
      );
    

Use it

  • Virgil does not replace the Navigator object, it only provides an extension to it.
  • To push a named page with arguments, use either
      Virgil.of(context).pushNamed('/hello', 'Arguments!');
    
    or
      Virgil.pushNamed(context, '/hello', 'Arguments!');
    
  • Virgil supports these methods
    • pushNamed
    • pushNamedAndRemoveUntil
    • pushReplacementNamed
    • popAndPushNamed
      • The interface should be the same for all of these, with the exception of an optional argument: named parameter
      • The argument is dynamic by default, you can use type arguments to specifiy a type yourself.
  • To pop, use
      Navigator.of(context).pop("value");
    
  • For compatibility, Virgil will call the navigator if it can't find the route within Inferno.
    • The arguments will be lost!

Custom Page Route Builder

  • You can provide Inferno with a custom PageRouteBuilder to customize the page transitions

[0.8.0] - First public release

  • First public release
  • Adding package to pub

[0.8.1] - Quick fix

  • Added comment for the Virgil class
  • Removed readme.md in the example

example/lib/main.dart

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

void main() => runApp(_App());

class _App extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
        theme: ThemeData.dark(),
        title: 'Virgil Example',
        home: Inferno(
          {
            '/': (context, arguments) => PageOne(),
            '/hello': (context, arguments) => PageTwo(arguments),
          },
        ).home(context),
      );
}

class PageOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final scaffoldKey = GlobalKey<ScaffoldState>();
    return Scaffold(
      key: scaffoldKey,
      appBar: AppBar(
        title: const Text('/'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            MaterialButton(
              child: const Text('pushNamed'),
              color: Colors.lightBlue,
              onPressed: () async {
                await Virgil.of(context).pushNamed<dynamic, String>('/hello',
                    arguments: 'pushNamed');
              },
            ),
            MaterialButton(
              child: const Text('pushReplacementNamed'),
              color: Colors.lightGreen,
              onPressed: () async {
                await Virgil.of(context).pushReplacementNamed('/hello',
                    arguments: 'pushReplacementNamed');
              },
            ),
          ],
        ),
      ),
    );
  }
}

class PageTwo extends StatelessWidget {
  const PageTwo(this.arg);

  final String arg;

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Scaffold(
          appBar: AppBar(
            title: const Text('/hello'),
          ),
          body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('You passed: $arg'),
                MaterialButton(
                  child: arg == 'pushReplacementNamed'
                      ? const Text('Re-open the home page')
                      : const Text('Close this page'),
                  color: arg == 'pushReplacementNamed'
                      ? Colors.lightGreen
                      : Colors.lightBlue,
                  onPressed: () {
                    if (arg == 'pushReplacementNamed') {
                      Virgil.of(context).pushReplacementNamed('/');
                      return;
                    }
                    Navigator.of(context).pop('You returned data!');
                  },
                )
              ],
            ),
          ),
        ),
      );
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  virgil: ^0.8.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:virgil/virgil.dart';
  
Version Uploaded Documentation Archive
0.8.1 Nov 4, 2018 Go to the documentation of virgil 0.8.1 Download virgil 0.8.1 archive
0.8.0 Nov 4, 2018 Go to the documentation of virgil 0.8.0 Download virgil 0.8.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8