alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

Fish-redux not exposing exceptions using catcher or runZoned ! #570

Closed karimiBadr closed 4 years ago

karimiBadr commented 4 years ago

I can't use catcher library (https://pub.dev/packages/catcher), because fish-redux not exposing exceptions even when i use runZoned !!

runZoned(() async {
  runApp(myApp());
}, onError: (error, stackTrace) async {
  await _reportError(error, stackTrace);
});
zjuwjf commented 4 years ago

Not Expected. Could you give a reproducible demo ?

karimiBadr commented 4 years ago

main.dart :


import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:flutter_app_test/home/page.dart';
import 'package:flutter_app_test/splash/page.dart';

void main() async {
  runZoned(
    () async {
      runApp(MyApp());
    },
    onError: (Object obj, StackTrace stack) {
      // Catch error exception
      print(obj);
      print(stack);
    },
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final AbstractRoutes routes = PageRoutes(
    pages: <String, Page<Object, dynamic>>{
      '/splash': SplashPage(),
      '/home': HomePage(),
    },
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MyApp',
      home: routes.buildPage('/splash', <String, dynamic>{}),
      onGenerateRoute: (RouteSettings settings) {
        return MaterialPageRoute<Object>(builder: (BuildContext context) {
          return routes.buildPage(settings.name, settings.arguments);
        });
      },
    );
  }
}

view.dart (splash)

import 'package:flutter/material.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    SplashState state, Dispatch dispatch, ViewService viewService) {
  return Scaffold(
    body: Center(
      child: RaisedButton(
        child: Text('throw Exception'),
        onPressed: () {
          throw Exception('error');
        },
      ),
    ),
  );
}

when i click 'throw exception' button the onError method inside runZoned is not triggered !!

thank you @zjuwjf

karimiBadr commented 4 years ago

it works fine in release mode ! Thx