Fred_Wolfe
Fred_Wolfe

Reputation: 832

Enums can't be instantiated

So I don't know how to explain this problem , but it has to do with the flutter custom Tabs and the deprecations. after running this code I get an error:

Future openLinkWithCustomTab(BuildContext context, String url) async {
    try {
      await FlutterWebBrowser.openWebPage(
        url: url,
        customTabsOptions: CustomTabsOptions(
          colorScheme: context.read<ThemeBloc>().darkTheme!
              ? CustomTabsColorScheme.dark
              : CustomTabsColorScheme.light,
          shareState: const CustomTabsShareState.enabled(),
          instantAppsEnabled: true,
          showTitle: true,
          urlBarHidingEnabled: true,
        ),
        safariVCOptions: const SafariViewControllerOptions(
          barCollapsingEnabled: true,
          dismissButtonStyle: SafariViewControllerDismissButtonStyle.close,
          modalPresentationCapturesStatusBarAppearance: true,
        ),
      );
    } catch (e) {
      openToast1(context, 'Cant launch the url');
      debugPrint(e.toString());
    }
  }

this is the error: lib/services/app_service.dart:66:29: Error: Enums can't be instantiated. shareState: const CustomTabsShareState.enabled(), ^^^^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

Process 'command 'E:\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

Upvotes: 0

Views: 578

Answers (1)

聂超群
聂超群

Reputation: 2120

Replace const CustomTabsShareState.enabled() with CustomTabsShareState.enabled.

I can not find enabled definition in CustomTabsShareState: CustomTabsShareState

So maybe you are using the wrong one. Try to change to CustomTabsShareState.on.

Refer to Enumerated types for more info.

Upvotes: 1

Related Questions