Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: stacked generate fails using generic types #1136

Open
akshdeep-singh opened this issue Oct 14, 2024 · 0 comments
Open

[bug]: stacked generate fails using generic types #1136

akshdeep-singh opened this issue Oct 14, 2024 · 0 comments

Comments

@akshdeep-singh
Copy link

Describe the bug

I have a Stacked view, which is generating fine, but as I add type to it, the stacked fails to generate routes for it.

What operating system do you use?

Windows

Information about the installed tooling

No response

Steps to reproduce the issue

  1. Following works fine:
class LoadingView extends StatefulWidget {
  const LoadingView({
    super.key,
    required this.future,
    required this.onSuccess,
    this.onError,
  });

  final Future Function() future;
  final void Function(dynamic) onSuccess;
  final void Function(dynamic)? onError;

  @override
  State<StatefulWidget> createState() => _LoadingViewState();
}

class _LoadingViewState extends State<LoadingView> {
  @override
  void initState() {
    super.initState();
    widget.future().then(
          (value) => widget.onSuccess(value),
          onError: widget.onError ??
              (e) {
                locator<NavigationService>().back();
                MySnackBar.showError(e);
              },
        );
  }

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: SafeArea(
        child: Center(
          child: CircularProgressIndicator(),
        ),
      ),
    );
  }
}
  1. Add type, and stacked generate fails:
class LoadingView<T> extends StatefulWidget {
  const LoadingView({
    super.key,
    required this.future,
    required this.onSuccess,
    this.onError,
  });

  final Future<T> Function() future;
  final void Function(T) onSuccess;
  final void Function(dynamic)? onError;

  @override
  State<StatefulWidget> createState() => _LoadingViewState<T>();
}

class _LoadingViewState<T> extends State<LoadingView<T>> {
  @override
  void initState() {
    super.initState();
    widget.future().then(
          (value) => widget.onSuccess(value),
          onError: widget.onError ??
              (e) {
                locator<NavigationService>().back();
                MySnackBar.showError(e);
              },
        );
  }

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: SafeArea(
        child: Center(
          child: CircularProgressIndicator(),
        ),
      ),
    );
  }
}

Expected behavior

No response

Screenshots

No response

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant