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

Flutter - Encountered a Error at an unrecoverable point. Failure was: #3775

Open
constantinLu opened this issue Mar 21, 2023 · 0 comments
Open
Labels
bug Something isn't working needs triage This issue requires triage

Comments

@constantinLu
Copy link

constantinLu commented Mar 21, 2023

Description
Sorry about labeling a bug, but I could not find any related label for my issue.
Error saying string value of a bloc state is empty, but when looking into the bloc observer the states are mapped correctly.

Steps To Reproduce

The problem that I have is that The BLocBuilder from AddressView it does not take into account the newly updated state.

From my undestanding is that the bloc state is updated to late since the BlocBuilder still takes the old value. (the empty value)

Class where the exception is thrown: AccountView.

Bloc is Provided in the app_widget.dart , then I add an event to the satefull class AccountView -> and build the view. (Crashes on the BlocBuilder).

In the BlocObserver the state changes correctly but when it reaches the BlocBuilder the initial value is taken into account and not the newly changed state with the initialized values.

class AppWidget extends StatelessWidget {
  static const String title = 'Vault Pass';

  const AppWidget({super.key});

  @override
  Widget build(BuildContext context) {
    final _appRouter = getIt<AppRouter>();

    /// PROVIDES ACCESS TO BLOCS TO THE CHILDREN
    return MultiBlocProvider(
      providers: [
        BlocProvider(
            create: (context) =>
                //adds event right away! with ..add()
                getIt<AuthBloc>()..add(const AuthEvent.authCheckRequest())),
        BlocProvider(create: (context) => getIt<RegisterBloc>()),
        BlocProvider(create: (context) => getIt<LoginBloc>()),
        BlocProvider(create: (context) => getIt<RecordBloc>()),
      ],
      child: MaterialApp.router(
        routerDelegate: _appRouter.delegate(),
        routeInformationParser: _appRouter.defaultRouteParser(),
        debugShowCheckedModeBanner: false,
        title: title,
        theme: ThemeData(
            primaryColor: blackJet,
            //TODO: add colors here //splashColor: grey!!!,
            textTheme: GoogleFonts.poppinsTextTheme(Theme.of(context).textTheme),
            colorScheme: ColorScheme.fromSwatch(primarySwatch: materialWhite),
            scaffoldBackgroundColor: blackFull),
      ),
    );
  }
}





class AccountView extends StatefulWidget {
  final Record record;

  const AccountView({required this.record, Key? key}) : super(key: key);

  @override
  State<AccountView> createState() => _AccountViewState();
}

class _AccountViewState extends State<AccountView> {
  @override
  void initState() {
    context.read<RecordBloc>().add(RecordEvent.initialized(fp.Option.of(widget.record)));
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return BlocBuilder<RecordBloc, RecordState>(
      builder: (context, state) {
        return WillPopScope(
          /// this makes the device button work to go back
          onWillPop: () {
            context.navigateBack();
            return Future.value(false);
          },
          child: Scaffold(
            backgroundColor: Palette.blackFull,
            body: SafeArea(
              child: CustomScrollView(
                slivers: [
                  SliverFillRemaining(
                    hasScrollBody: false,
                    child: Padding(
                      padding: const EdgeInsets.fromLTRB(8, 20, 8, 8),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          //! RECORD TYPE
                          _RecordTypeWidget(value: state.record.type.value.toLowerCase()),
                          const Divider(height: 10, thickness: 1, color: Colors.white),
                          const SizedBox(height: 10),

                          //! RECORD NAME
                          ViewCardWidget(
                              textWidget: {"Record name": state.record.recordName.get()},
                              cardHeight: 12),

                          //! Title
                          Padding(
                            padding: const EdgeInsets.fromLTRB(15, 15, 10, 2),
                            child: Text("Credentials", style: bodyText(12, Palette.greySpanish)),
                          ),

                          //! RECORD LOGIN AND PASSWORD
                          ViewCardWidget(textWidget: {
                            "Login": state.record.loginRecord.get(),
                            "Password": state.record.passwordRecord.get()
                          }, cardHeight: 24),

                          //! URL
                          ViewCardWidget(
                              textWidget: {"Url": state.record.url.get()}, cardHeight: 12),

                          //! DESCRIPTION
                          ViewCardWidget(
                              textWidget: {"Description": state.record.description.get()},
                              cardHeight: 12),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat,
            floatingActionButton: _SpeedDialFabWidget(recordId: state.record.id),
          ),
        );
      },
    );
  }
}

You can clone the project from: https://github.com/gizet/vault_pass if you like to take a look.

Expected Behavior

  • should map the next mapped state values

Screenshots
image

StackTrace:

======== Exception caught by widgets library =======================================================
The following UnexpectedValueError was thrown building BlocBuilder<RecordBloc, RecordState>(dirty, dependencies: [_InheritedProviderScope<RecordBloc?>], state: _BlocBuilderBaseState<RecordBloc, RecordState>#77787):
"Encountered a Error at an unrecoverable point. Failure was: MicroTypeFailure<String>.invalidString(failedValue: )"

The relevant error-causing widget was: 
  BlocBuilder<RecordBloc, RecordState> BlocBuilder:file:///D:/_workspace/flutter/vault_pass/lib/presentation/view/records/account/account_view.dart:37:12
When the exception was thrown, this was the stack: 
#0      MicroType.get.<anonymous closure> (package:vault_pass/domain/microtypes/microtype.dart:15:30)
#1      Left.match (package:fpdart/src/either.dart:592:72)
#2      Either.fold (package:fpdart/src/either.dart:255:7)
#3      MicroType.get (package:vault_pass/domain/microtypes/microtype.dart:15:18)
#4      _AccountViewState.build.<anonymous closure> (package:vault_pass/presentation/view/records/account/account_view.dart:64:83)
#5      BlocBuilder.build (package:flutter_bloc/src/bloc_builder.dart:90:57)
#6      _BlocBuilderBaseState.build (package:flutter_bloc/src/bloc_builder.dart:166:21)
#7      StatefulElement.build (package:flutter/src/widgets/framework.dart:5080:27)
#8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4968:15)
#9      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5133:11)
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:4690:5)
#11     StatefulElement.update (package:flutter/src/widgets/framework.dart:5156:5)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3660:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4993:16)
#14     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5133:11)
#15     Element.rebuild (package:flutter/src/widgets/framework.dart:4690:5)
#16     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2743:19)
#17     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:863:21)
#18     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:381:5)
#19     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#20     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1218:9)
#21     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:942:7)
#25     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
(elided 3 frames from class _Timer and dart:async-patch)
====================================================================================================
Reloaded 2 of 1556 libraries in 1,742ms (compile: 40 ms, reload: 338 ms, reassemble: 1243 ms).
D/EGL_emulation( 6445): app_time_stats: avg=53314.34ms min=53314.34ms max=53314.34ms count=1

Additional Context

  • found this related issued from some time ago.
  • it looks like is the same issue that I have, but there is no obvious fix there. Bloc getting value error #1266
@constantinLu constantinLu added the bug Something isn't working label Mar 21, 2023
@felangel felangel added the needs triage This issue requires triage label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage This issue requires triage
Projects
None yet
Development

No branches or pull requests

2 participants