gurleensethi / sailor

Easy page navigation and management in Flutter apps.
https://pub.dev/packages/sailor
MIT License
145 stars 24 forks source link

Sailor not working at all #39

Closed peterson-umoke closed 4 years ago

peterson-umoke commented 4 years ago

Good day, i am trying out sailor for the first time, and i am not finding it funny. i have just setup a new application and trying out sailor but it keeps giving this error,

Compiler message: /C:/tools/flutter/.pub-cache/hosted/pub.dartlang.org/sailor-0.7.0/lib/src/sailor.dart:429:43: Error: Can't return a value from a void function. return this.navigatorKey.currentState.pop(result); ^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.

Please here is the code block for you perusual.

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

void main() {
  Routes.createRoutes();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
      onGenerateRoute: Routes.sailor.generator(),
      navigatorKey: Routes.sailor.navigatorKey,
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class SecondPage extends StatelessWidget {
  const SecondPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("This is the second page"),
    );
  }
}

class ThirdPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("This is the third page"),
    );
  }
}

class Routes {
  static final sailor = Sailor();

  static void createRoutes() {
    sailor.addRoutes(
      [
        SailorRoute(
          name: "/first-page",
          builder: (context, args, param) => MyHomePage(),
        ),
        SailorRoute(
          name: "/second-page",
          builder: (context, args, param) => SecondPage(),
        ),
        SailorRoute(
          name: "/third-page",
          builder: (context, args, param) => ThirdPage(),
        ),
      ],
    );
  }
}

Thanks. I love the syntax of sailor but i am unable to use it

26

peterson-umoke commented 4 years ago

This issue keeps happening to other people, in case anyone happens to stumble on this, kindly update your pubspec.yaml file to this

sailor:
    git:
      url: git://github.com/peterson-umoke/sailor.git
      ref: master