lukepighetti / fluro

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
https://pub.dev/packages/fluro
MIT License
3.67k stars 417 forks source link

Example is over-engineerd #251

Open lil5 opened 3 years ago

lil5 commented 3 years ago

To read and understand how fluro work I have needed to read 5+ files. Meanwhile having implemented fluro into my project only using 2 files for route initialization.

Might I suggest something like this?

// /main.dart
import 'package:flutter/material.dart';
import 'app/router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyApp extends State<MyApp> {
  final router = Routes.getRouter();

  // render
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      initialRoute: '/',
      onGenerateRoute: router.generator,
    );
  }
}
// /app/router.dart
import 'package:fluro/fluro.dart';

class Routes {
  static FluroRouter getRouter() {
    final router = FluroRouter();

    router.define(
      "/",
      handler: Handler(handlerFunc: (context, params) => const HomePage()),
    );
    router.define(
      "/chat",
      handler: Handler(handlerFunc: (context, params) => const SecondPage()),
      transitionType: TransitionType.fadeIn,
    );

    return router;
  }
}
ignertic commented 3 years ago

I'm actually gonna use this to try out the package

lil5 commented 2 years ago

@lukepighetti Would you be interested in receiving a Pull Request replacing or adding this example?

If so I will try to make the time to create one.