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

Using Device Preview runs all of my initState twice #252

Open
manandharsudhir opened this issue Aug 30, 2024 · 0 comments
Open

Using Device Preview runs all of my initState twice #252

manandharsudhir opened this issue Aug 30, 2024 · 0 comments

Comments

@manandharsudhir
Copy link

manandharsudhir commented Aug 30, 2024

Here is my main Code

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferencesImp.init();

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  ApiConstants.url = "my api";
  runApp(
    DevicePreview(
      enabled: true,
      builder: (context) => ProviderScope(child: const MyApp()),
    ),
  );
}

here is my MyApp code

final appRouter = AppRouter();

class MyApp extends HookConsumerWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return MaterialApp.router(
      routerDelegate: appRouter.delegate(),
      routeInformationParser: appRouter.defaultRouteParser(),
      title: AppStrings.appname,
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [],
      builder: (context, widget) {
        widget = ResponsiveBreakpoints.builder(
          child: DevicePreview.appBuilder(context, widget),
          breakpoints: const [
            Breakpoint(start: 0, end: 450, name: MOBILE),
            Breakpoint(start: 451, end: 800, name: TABLET),
            Breakpoint(start: 801, end: 1920, name: DESKTOP),
            Breakpoint(start: 1921, end: double.infinity, name: '4K'),
          ],
        );
        return widget;
      },
    );
  }
}

now when i run init state on any of my screen the function is being called twice.

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