cruiser 1.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new57

cruiser #

Cruiser is a fully featured router library for Flutter applications.

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[1.0.0] #

  • Initial release.

[1.1.0] #

  • Added additional transitions

[1.2.0] #

  • Fixed exit transitions
  • Added additional transitions

[1.2.1] #

  • Added slide transition

[1.2.2] #

  • Fixed a pop() related exception
  • Added additional parallax transitions

[1.2.3] #

  • Updated async methods

example/lib/main.dart

import 'dart:math';
import 'package:cruiser/cruiser.dart';
import 'package:cruiser_example/example_args.dart';
import 'package:cruiser_example/utils/color_converter.dart';
import 'package:cruiser_example/utils/cruiser_transition_extensions.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

const colors = [Colors.blue, Colors.green, Colors.purple, Colors.orange, Colors.pink, Colors.amber, Colors.cyan];

const routeName = '/example';
//const routeNameSecond = '/second-example';

final router = Cruiser();

final random = Random();

//bool isSecondRoute = false;

void main() 
{
    router.addRoute(CruiserRoute(name: routeName, builder: (context, args) => ExamplePage(args: args)));
 //   router.addRoute(CruiserRoute(name: routeNameSecond, builder: (context, args) => SecondExamplePage(args: args)));

    runApp(MyApp());
}

class MyApp extends StatelessWidget 
{
    @override
    Widget build(BuildContext context) 
    {
        return MaterialApp(
            title: 'Cruiser Example',
            initialRoute: routeName,
            navigatorKey: router.navigatorKey,
            onGenerateRoute: router.generator,
            navigatorObservers: [router.observer],
            //home: ExamplePage(args: null),
            /*builder: (BuildContext context, Widget child)
            {
                return WillPopScope(
                    child: Scaffold(
                        resizeToAvoidBottomInset: true,
                        body: DefaultTextStyle(
                            style: TextStyle(fontSize: 16, color: Colors.white),
                            child: child
                        )
                    ), 
                    onWillPop: () async 
                    {
                        return Future.value(false);
                    }
                );
            }*/
        );
    }
}

class SecondExamplePage extends ExamplePage
{
    final ExampleArgs args;

    SecondExamplePage({@required this.args}): super(args: args);

    @override
    ExamplePageState createState() => new ExamplePageState();
}

class ExamplePage extends StatefulWidget
{
    final ExampleArgs args;

    ExamplePage({@required this.args});

    @override
    ExamplePageState createState() => new ExamplePageState();
}

class ExamplePageState extends State<ExamplePage>
{
    Color nextColor;
    TransitionType nextTransition;

    @override
    void initState() 
    {    
        super.initState();

        nextColor = _getNextColor(widget.args?.color);
        nextTransition = _getNextTransition(widget.args?.transition);
   }

    @override
    Widget build(BuildContext context)
    {   
        return WillPopScope(
            child: Scaffold(
                resizeToAvoidBottomInset: true,
                body: DefaultTextStyle(
                    style: TextStyle(fontSize: 16, color: Colors.white),
                    child: Container(
                        color: widget.args?.color ?? Colors.white,
                        child: SafeArea(
                            child: Center(
                                child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                        ExampleButton(
                                            text: '${nextTransition.name}', // '${isSecondRoute ? 'Second': 'First'} 
                                            color: ColorConverter.darken(widget.args?.color ?? Colors.blue, 0.1),
                                            onPressed: () async => await _toNextRoute(context)
                                        )
                                    ]
                                )
                            )
                        ),
                    )
                )
            ), 
            onWillPop: () async 
            {
                router.pop();
                return Future.value(false);
            }
        );
    }

    Future _toNextRoute(BuildContext context) async 
    {
    /*    isSecondRoute = !isSecondRoute;

        if(isSecondRoute)
        {
            await router.navigate(
                context, 
                routeNameSecond, 
                transition: TransitionType.secondZoomIn,
                args: ExampleArgs(color: nextColor, transition: nextTransition));
        }
        else
        {
            await router.navigate(
                context, 
                routeName, 
                transition: TransitionType.zoomIn,
                args: ExampleArgs(color: nextColor, transition: nextTransition)); 
        }

        return;

        final route = isSecondRoute ? routeNameSecond : routeName;
        isSecondRoute = !isSecondRoute;
*/
        await router.navigate(
            context, 
            routeName, 
            transition: nextTransition,
            args: ExampleArgs(color: nextColor, transition: nextTransition)
        ); 
    }

    TransitionType _getNextTransition(TransitionType previousTransition)
    {   
        if(previousTransition == null) return TransitionType.values[0];

        var index = TransitionType.values.indexOf(previousTransition) + 1;

        return TransitionType.values[index < TransitionType.values.length ? index : 0];
    }

    Color _getNextColor(Color previousColor)
    {
        var available = previousColor != null ? colors.where((x) => x != previousColor).toList() : colors;

        return available[random.nextInt(available.length)];
    }
}

class ExampleButton extends StatelessWidget
{
    final VoidCallback onPressed;
    final String text;
    final Color color;

    ExampleButton({this.text, this.onPressed, this.color});

    @override
    Widget build(BuildContext context) 
    {
        return ButtonTheme(
            height: 47,
            padding: EdgeInsets.symmetric(horizontal: 25),
            child: FlatButton(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(4.0),
                ),
                color: color,
                textColor: Colors.white,
                onPressed: onPressed,
                child: Text(text, style: TextStyle(fontSize: 14))
            )
        );
    }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cruiser: ^1.2.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:cruiser/cruiser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • cruiser that is a package requiring null.

Health suggestions

Fix lib/src/models/cruiser_transition.dart. (-0.50 points)

Analysis of lib/src/models/cruiser_transition.dart reported 1 hint:

line 1 col 8: Unused import: 'package:cruiser/src/transitions/zoom_in_transition.dart'.

Format lib/cruiser.dart.

Run flutter format to format lib/cruiser.dart.

Format lib/src/cruiser.dart.

Run flutter format to format lib/src/cruiser.dart.

Fix additional 27 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/cruiser_page_route.dart (Run flutter format to format lib/src/cruiser_page_route.dart.)
  • lib/src/enums/transition_type.dart (Run flutter format to format lib/src/enums/transition_type.dart.)
  • lib/src/errors/route_not_found.dart (Run flutter format to format lib/src/errors/route_not_found.dart.)
  • lib/src/logger/cruiser_logger.dart (Run flutter format to format lib/src/logger/cruiser_logger.dart.)
  • lib/src/models/arguments_wrapper.dart (Run flutter format to format lib/src/models/arguments_wrapper.dart.)
  • lib/src/models/cruiser_options.dart (Run flutter format to format lib/src/models/cruiser_options.dart.)
  • lib/src/models/cruiser_route.dart (Run flutter format to format lib/src/models/cruiser_route.dart.)
  • lib/src/navigator_observers/cruiser_logging_observer.dart (Run flutter format to format lib/src/navigator_observers/cruiser_logging_observer.dart.)
  • lib/src/navigator_observers/cruiser_stack_observer.dart (Run flutter format to format lib/src/navigator_observers/cruiser_stack_observer.dart.)
  • lib/src/transitions/accordion_transition.dart (Run flutter format to format lib/src/transitions/accordion_transition.dart.)
  • lib/src/transitions/background_to_foreground_transition.dart (Run flutter format to format lib/src/transitions/background_to_foreground_transition.dart.)
  • lib/src/transitions/cube_transition.dart (Run flutter format to format lib/src/transitions/cube_transition.dart.)
  • lib/src/transitions/depth_transition.dart (Run flutter format to format lib/src/transitions/depth_transition.dart.)
  • lib/src/transitions/empty_transition.dart (Run flutter format to format lib/src/transitions/empty_transition.dart.)
  • lib/src/transitions/flip_horizontal_transition.dart (Run flutter format to format lib/src/transitions/flip_horizontal_transition.dart.)
  • lib/src/transitions/flip_vertical_transition.dart (Run flutter format to format lib/src/transitions/flip_vertical_transition.dart.)
  • lib/src/transitions/foreground_to_background_transition.dart (Run flutter format to format lib/src/transitions/foreground_to_background_transition.dart.)
  • lib/src/transitions/parallax_left.dart (Run flutter format to format lib/src/transitions/parallax_left.dart.)
  • lib/src/transitions/parallax_top.dart (Run flutter format to format lib/src/transitions/parallax_top.dart.)
  • lib/src/transitions/parallax_transition.dart (Run flutter format to format lib/src/transitions/parallax_transition.dart.)
  • lib/src/transitions/rotate_down_transition.dart (Run flutter format to format lib/src/transitions/rotate_down_transition.dart.)
  • lib/src/transitions/rotate_up_transition.dart (Run flutter format to format lib/src/transitions/rotate_up_transition.dart.)
  • lib/src/transitions/slide_transition.dart (Run flutter format to format lib/src/transitions/slide_transition.dart.)
  • lib/src/transitions/stack_transition.dart (Run flutter format to format lib/src/transitions/stack_transition.dart.)
  • lib/src/transitions/tablet_transition.dart (Run flutter format to format lib/src/transitions/tablet_transition.dart.)
  • lib/src/transitions/zoom_in_transition.dart (Run flutter format to format lib/src/transitions/zoom_in_transition.dart.)
  • lib/src/transitions/zoom_out_slide_transition.dart (Run flutter format to format lib/src/transitions/zoom_out_slide_transition.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://leadcode.dev was unreachable.

Repository URL doesn't exist. (-10 points)

At the time of the analysis the repository field https://github.com/bratan/cruiser was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety