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

Error: Type 'FormBloc' can't use itself as a bound. #339

Open
mvofreire opened this issue Nov 19, 2023 · 15 comments
Open

Error: Type 'FormBloc' can't use itself as a bound. #339

mvofreire opened this issue Nov 19, 2023 · 15 comments

Comments

@mvofreire
Copy link

Hey Guys!
Looks like the last flutter upgrade is breaking this package.

image

image

@Sander0542
Copy link

I am having the same issue, is there any solution yet?

@cavin-macwan
Copy link

I'm also having the same issue

@richard457
Copy link

Anyone who managed to have it solved on local branch please??

@cavin-macwan
Copy link

Change the complete code of this file: root/packages/flutter_form_bloc/lib/src/form_bloc_listener.dart

import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:form_bloc/form_bloc.dart' as form_bloc;

typedef FormBlocListenerCallback<
        FormBlocState2 extends form_bloc
        .FormBlocState<SuccessResponse, ErrorResponse>,
        SuccessResponse,
        ErrorResponse>
    = void Function(BuildContext context, FormBlocState2 state);

/// [BlocListener] that reacts to the state changes of the FormBloc.
class FormBlocListener<
        FormBloc2 extends form_bloc.FormBloc<SuccessResponse, ErrorResponse>,
        SuccessResponse,
        ErrorResponse>
    extends BlocListener<FormBloc2,
        form_bloc.FormBlocState<SuccessResponse, ErrorResponse>> {
  /// [BlocListener] that reacts to the state changes of the FormBloc.
  /// {@macro bloclistener}
  FormBlocListener({
    Key? key,
    this.formBloc,
    Widget? child,
    this.onLoading,
    this.onLoaded,
    this.onLoadFailed,
    this.onSubmitting,
    this.onSuccess,
    this.onFailure,
    this.onSubmissionCancelled,
    this.onSubmissionFailed,
    this.onDeleting,
    this.onDeleteFailed,
    this.onDeleteSuccessful,
  }) : super(
          key: key,
          child: child,
          bloc: formBloc,
          listenWhen: (previousState, state) =>
              previousState.runtimeType != state.runtimeType,
          listener: (context, state) {
            if (state is form_bloc.FormBlocLoading<SuccessResponse, ErrorResponse> &&
                onLoading != null) {
              onLoading(context, state);
            } else if (state is form_bloc.FormBlocLoaded<SuccessResponse, ErrorResponse> &&
                onLoaded != null) {
              onLoaded(context, state);
            } else if (state is form_bloc.FormBlocLoadFailed<SuccessResponse, ErrorResponse> &&
                onLoadFailed != null) {
              onLoadFailed(context, state);
            } else if (state is form_bloc
                    .FormBlocSubmitting<SuccessResponse, ErrorResponse> &&
                onSubmitting != null) {
              onSubmitting(context, state);
            } else if (state is form_bloc.FormBlocSuccess<SuccessResponse, ErrorResponse> &&
                onSuccess != null) {
              onSuccess(context, state);
            } else if (state is form_bloc.FormBlocFailure<SuccessResponse, ErrorResponse> &&
                onFailure != null) {
              onFailure(context, state);
            } else if (state is form_bloc.FormBlocSubmissionCancelled<SuccessResponse, ErrorResponse> &&
                onSubmissionCancelled != null) {
              onSubmissionCancelled(context, state);
            } else if (state is form_bloc
                    .FormBlocSubmissionFailed<SuccessResponse, ErrorResponse> &&
                onSubmissionFailed != null) {
              onSubmissionFailed(context, state);
            } else if (state is form_bloc.FormBlocDeleting<SuccessResponse, ErrorResponse> &&
                onDeleting != null) {
              onDeleting(context, state);
            } else if (state is form_bloc
                    .FormBlocDeleteFailed<SuccessResponse, ErrorResponse> &&
                onDeleteFailed != null) {
              onDeleteFailed(context, state);
            } else if (state is form_bloc
                    .FormBlocDeleteSuccessful<SuccessResponse, ErrorResponse> &&
                onDeleteSuccessful != null) {
              onDeleteSuccessful(context, state);
            }
          },
        );

  /// {@macro form_bloc.form_state.FormBlocLoading}
  final FormBlocListenerCallback<
      form_bloc.FormBlocLoading<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onLoading;

  /// {@macro form_bloc.form_state.FormBlocLoaded}
  final FormBlocListenerCallback<
      form_bloc.FormBlocLoaded<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onLoaded;

  /// {@macro form_bloc.form_state.FormBlocLoadFailed}
  final FormBlocListenerCallback<
      form_bloc.FormBlocLoadFailed<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onLoadFailed;

  /// {@macro form_bloc.form_state.FormBlocSubmitting}
  final FormBlocListenerCallback<
      form_bloc.FormBlocSubmitting<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onSubmitting;

  /// {@macro form_bloc.form_state.FormBlocSuccess}
  final FormBlocListenerCallback<
      form_bloc.FormBlocSuccess<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onSuccess;

  /// {@macro form_bloc.form_state.FormBlocFailure}
  final FormBlocListenerCallback<
      form_bloc.FormBlocFailure<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onFailure;

  /// {@macro form_bloc.form_state.FormBlocSubmissionCancelled}
  final FormBlocListenerCallback<
      form_bloc.FormBlocSubmissionCancelled<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onSubmissionCancelled;

  /// {@macro form_bloc.form_state.FormBlocSubmissionFailed}
  final FormBlocListenerCallback<
      form_bloc.FormBlocSubmissionFailed<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onSubmissionFailed;

  /// {@macro form_bloc.form_state.FormBlocSubmissionFailed}
  final FormBlocListenerCallback<
      form_bloc.FormBlocDeleting<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onDeleting;

  /// {@macro form_bloc.form_state.FormBlocSubmissionFailed}
  final FormBlocListenerCallback<
      form_bloc.FormBlocDeleteFailed<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onDeleteFailed;

  /// {@macro form_bloc.form_state.FormBlocSubmissionFailed}
  final FormBlocListenerCallback<
      form_bloc.FormBlocDeleteSuccessful<SuccessResponse, ErrorResponse>,
      SuccessResponse,
      ErrorResponse>? onDeleteSuccessful;

  /// If the [formBloc] parameter is omitted, [FormBlocListener]
  /// will automatically perform a lookup using
  /// [BlocProvider].of<[FormBloc]> and the current [BuildContext].
  final FormBloc2? formBloc;

  /// The [Widget] which will be rendered as a descendant of the [BlocListener].
  @override
  Widget? get child => super.child;
}

@fiurthorn
Copy link

for me its a compiler bug flutter/flutter#138785 not a formbloc bug.
there an example to reproduce the bug.

@pratik-7span
Copy link

I am also facing the same issue. Any solution other than flutter downgrade?

@pratik-7span
Copy link

For a quick fix, you can use the forked version of @Cavin6080 as below:

  # flutter_form_bloc: ^0.31.0
  flutter_form_bloc:
    git:
      url: https://github.com/Cavin6080/form_bloc.git
      path: packages/flutter_form_bloc

I hope it will help you.

@fiurthorn
Copy link

If someone interested to fix it, open a issue @dart/language repos.

@hunterino
Copy link

Same problem

Reproduction steps:

Created a new project
Added flutter_form_bloc
flutter pub add flutter_form_bloc
copied example from pub.dev
attempted to run the application for mac_os, and web.

Flutter doctor Results

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.0, on macOS 14.1.1 23B81 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
[✓] VS Code (version 1.84.2)
[✓] Connected device (2 available)
[✓] Network resources

Error Log

../../../.pub-cache/hosted/pub.dev/flutter_form_bloc-0.31.0/lib/src/form_bloc_listener.dart:6:9: Error: Type 'FormBlocState' can't use itself as a bound.
Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle.
        FormBlocState extends form_bloc
        ^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/flutter_form_bloc-0.31.0/lib/src/form_bloc_listener.dart:14:9: Error: Type 'FormBloc' can't use itself as a bound.
Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle.
        FormBloc extends form_bloc.FormBloc<SuccessResponse, ErrorResponse>,
        ^^^^^^^^
../../../.pub-cache/hosted/pub.dev/flutter_form_bloc-0.31.0/lib/src/form_bloc_listener.dart:17:13: Error: Type argument 'FormBloc' doesn't conform to the bound 'StateStreamable<S>' of the type variable 'B' on 'BlocListener'.
 - 'StateStreamable' is from 'package:bloc/src/bloc.dart' ('../../../.pub-cache/hosted/pub.dev/bloc-8.1.2/lib/src/bloc.dart').
Try changing type arguments so that they conform to the bounds.
    extends BlocListener<FormBloc,
            ^
../../../.pub-cache/hosted/pub.dev/flutter_bloc-8.1.3/lib/src/bloc_listener.dart:76:20: Context: This is the type variable whose bound isn't conformed to.
class BlocListener<B extends StateStreamable<S>, S>
                   ^
Target kernel_snapshot failed: Exception

Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Exception: Build process failed

@fiurthorn
Copy link

fyi dart-lang/sdk#54164

@94Sip
Copy link

94Sip commented Dec 7, 2023

Thank you for the quick fix @Cavin6080

Any idea on who owns this, in terms of fixing? Should this be with flutter_form_bloc or with the flutter team?

@cavin-macwan
Copy link

Hi @94Sip,

I think this issue is with the new update of Dart as far as I can tell. But the fix is quite easy, thus it would make sense as of now to just make the changes according to it so that people don't run into those issues.

@fiurthorn
Copy link

fiurthorn commented Dec 7, 2023

@94Sip the Bug is accepted by the dart/sdk team here: dart-lang/sdk#54164.
I don't know when it will be fixed. 4me i move to https://pub.dev/packages/reactive_forms, since it is more lightweight.

@AncientPixel
Copy link

Also slowly migrating to reactive_forms as it seems this project is dead.

@vasilich6107
Copy link

Hey @AncientPixel
check other very useful projects for reactive_forms

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

10 participants