getx icon indicating copy to clipboard operation
getx copied to clipboard

点击Get.snackbar,出现错误 No Overlay widget found. Some widgets require an Overlay widget ancestor for correct operation.

Open platojobs opened this issue 5 months ago • 8 comments

点击Get.snackbar,出现错误 No Overlay widget found. Some widgets require an Overlay widget ancestor for correct operation.

platojobs avatar Nov 22 '25 07:11 platojobs

happens since upgrade to flutter 3.38.1

tl0601 avatar Nov 23 '25 18:11 tl0601

add builder inside GetMaterialApp will fix

Image

thanhphamtrung avatar Nov 24 '25 01:11 thanhphamtrung

Added this in your main.dart

 // ----------- BUILDER UNTUK OVERLAY -----------
      builder: (context, child) {
        return Overlay(
          initialEntries: [OverlayEntry(builder: (_) => child!)],
        );
      },

EXAMPLE


import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:hazard_komik/home_webview_screen.dart';
import 'package:hazard_komik/test.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      // home: HomeWebViewScreen(),
      home: TextScreen(),

      // ----------- BUILDER UNTUK OVERLAY -----------
      builder: (context, child) {
        return Overlay(
          initialEntries: [OverlayEntry(builder: (_) => child!)],
        );
      },
      //
    );
  }
}

class TextScreen extends StatelessWidget {
  const TextScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Center(
            child: GestureDetector(
                onTap: () {
                  Get.snackbar("OK", "Snackbar Show");
                  print("Snackbar Print");
                },
                child: Container(
                    decoration: BoxDecoration(color: Colors.green),
                    child: Padding(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 20, vertical: 10),
                      child: Text(
                        "Button Snackbar",
                        style: TextStyle(color: Colors.white),
                      ),
                    ))),
          )
        ],
      ),
    );
  }
}

tedijumadi avatar Nov 24 '25 02:11 tedijumadi

Added this in your main.dart

// ----------- BUILDER UNTUK OVERLAY ----------- builder: (context, child) { return Overlay( initialEntries: [OverlayEntry(builder: (_) => child!)],      );       }, EXAMPLE

import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:get/get_navigation/src/root/get_material_app.dart'; import 'package:hazard_komik/home_webview_screen.dart'; import 'package:hazard_komik/test.dart';

void main() { runApp(const MyApp()); }

class MyApp extends StatelessWidget { const MyApp({super.key});

// This widget is the root of your application. @override Widget build(BuildContext context) { return GetMaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // TRY THIS: Try running your application with "flutter run". You'll see // the application has a purple toolbar. Then, without quitting the app, // try changing the seedColor in the colorScheme below to Colors.green // and then invoke "hot reload" (save your changes or press the "hot // reload" button in a Flutter-supported IDE, or press "r" if you used // the command line to start the app). // // Notice that the counter didn't reset back to zero; the application // state is not lost during the reload. To reset the state, use hot // restart instead. // // This works for code too, not just values: Most code changes can be // tested with just a hot reload. colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), // home: HomeWebViewScreen(), home: TextScreen(),

  // ----------- BUILDER UNTUK OVERLAY -----------
  builder: (context, child) {
    return Overlay(
      initialEntries: [OverlayEntry(builder: (_) => child!)],
    );
  },
  //
);

} }

class TextScreen extends StatelessWidget { const TextScreen({super.key});

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Center( child: GestureDetector( onTap: () { Get.snackbar("OK", "Snackbar Show"); print("Snackbar Print"); }, child: Container( decoration: BoxDecoration(color: Colors.green), child: Padding( padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 10), child: Text( "Button Snackbar", style: TextStyle(color: Colors.white), ), ))), ) ], ), ); } }

it works with this. thanks! :)

tl0601 avatar Nov 24 '25 11:11 tl0601

I've sent a patch to fix this, please check if it resolves the issue for you.

jonataslaw avatar Nov 24 '25 18:11 jonataslaw

@jonataslaw it resolves the issue for me,thanks!

platojobs avatar Nov 25 '25 11:11 platojobs

@jonataslaw Please fix in prerelease 5.0.0-release-candidate-9.3.2 too

mohammedkh96 avatar Nov 28 '25 12:11 mohammedkh96

my code works again using this hot fix / workaround 👍

 // ----------- BUILDER UNTUK OVERLAY -----------
      builder: (context, child) {
        return Overlay(
          initialEntries: [OverlayEntry(builder: (_) => child!)],
        );
      },

please notify me how to migrate from using the workaround when this bug solved, thank you 👍

MSyarifH avatar Dec 01 '25 08:12 MSyarifH