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

Materail 2 App is not shown with BannerAds #850

Closed
kmemo opened this issue May 22, 2023 · 1 comment
Closed

Materail 2 App is not shown with BannerAds #850

kmemo opened this issue May 22, 2023 · 1 comment
Labels
solved issue is closed as solved

Comments

@kmemo
Copy link

kmemo commented May 22, 2023

Plugin Version

Tested with 3.0.0 and 2.3.0

Steps to Reproduce

Setting "useMaterial3: false" in ThemeData of MatrialApp of existing App with BannerAds.

MatrialApp(
  theme: ThemeData(
    useMaterial3: false,
    .....
  )
)
  1. Run flutter create bug.
  2. Update the files as follows: ...
  3. ...
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await MobileAds.instance.initialize();
  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 MaterialApp(
      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 blue 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: false,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late BannerAd myBannerAd;
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  void initState() {
    super.initState();
    myBannerAd = BannerAd(
      adUnitId: (Platform.isAndroid)? 'ca-app-pub-3940256099942544/6300978111'
          : 'ca-app-pub-3940256099942544/2934735716',
      request: const AdRequest(),
      size: AdSize.fullBanner,
      listener: BannerAdListener(
        onAdLoaded: (_) {
          if (kDebugMode) {
            print('AdMob: Loaded a banner ad');
          }
          setState(() { });
        },
        onAdFailedToLoad: (ad, err) {
          if (kDebugMode) {
            print('AdMob: Failed to load a banner ad: ${err.message}');
          }
          ad.dispose();
        },
      ),
    );
    myBannerAd.load();
  }

  @override
  void dispose() {
    myBannerAd.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.

      bottomNavigationBar: BottomAppBar(
        child: Align(
          alignment: Alignment.bottomCenter,
          child: SafeArea(
            child: SizedBox(
              width: myBannerAd.size.width.toDouble(),
              height: myBannerAd.size.height.toDouble(),
              child: AdWidget(ad: myBannerAd),
            ),
          ),
        ),
      ),
    );
  }
}

Expected results:
App with BannerAds in the bottomNavigatorBar

Actual results:
BannerAds in the bottomNavigatorBar but no app visivle

Logs
Performing hot restart...
Syncing files to device sdk gphone64 arm64...
D/EGL_emulation(26848): app_time_stats: avg=627.75ms min=3.95ms max=10359.36ms count=17
Restarted application in 977ms.
D/DynamitePackage(26848): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/Ads     (26848): Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("D*********F950EAB************")) to get test ads on this device.
W/ConnectionStatusConfig(26848): Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START
D/EGL_emulation(26848): app_time_stats: avg=721.36ms min=15.10ms max=11097.55ms count=16
D/EGL_emulation(26848): eglCreateContext: 0xb4000070f6f913d0: maj 3 min 0 rcv 3
I/PlatformViewsController(26848): Hosting view in view hierarchy for platform view: 0
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
W/Parcel  (26848): Expecting binder but got null!
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
D/EGL_emulation(26848): app_time_stats: avg=1344.84ms min=1344.84ms max=1344.84ms count=1
I/DynamiteModule(26848): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:224400003
I/DynamiteModule(26848): Selected remote version of com.google.android.gms.ads.dynamite, version >= 224400003
D/EGL_emulation(26848): app_time_stats: avg=250.03ms min=16.64ms max=584.44ms count=5
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
I/flutter (26848): AdMob: Loaded a banner ad
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
D/EGL_emulation(26848): app_time_stats: avg=421.72ms min=13.96ms max=1330.14ms count=5
D/EGL_emulation(26848): app_time_stats: avg=521.02ms min=17.74ms max=1331.27ms count=4
D/EGL_emulation(26848): app_time_stats: avg=485.82ms min=47.79ms max=1327.57ms count=3
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
I/Ads     (26848): Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("D*********F950EAB************")) to get test ads on this device.
W/ConnectionStatusConfig(26848): Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE
W/ConnectionStatusConfig(26848): Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START
D/EGL_emulation(26848): eglCreateContext: 0xb4000070f6f97010: maj 3 min 0 rcv 3
I/DynamiteModule(26848): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:224400003
I/DynamiteModule(26848): Selected remote version of com.google.android.gms.ads.dynamite, version >= 224400003
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
D/EGL_emulation(26848): app_time_stats: avg=3856.58ms min=12.72ms max=69051.91ms count=18
D/EGL_emulation(26848): app_time_stats: avg=3856.79ms min=13.68ms max=69066.25ms count=18
D/EGL_emulation(26848): app_time_stats: avg=3859.77ms min=12.57ms max=69111.72ms count=18
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
I/flutter (26848): AdMob: Loaded a banner ad
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
D/EGL_emulation(26848): app_time_stats: avg=493.79ms min=67.65ms max=1313.83ms count=3
D/EGL_emulation(26848): app_time_stats: avg=471.02ms min=11.49ms max=1314.94ms count=3
D/EGL_emulation(26848): app_time_stats: avg=490.04ms min=42.35ms max=1316.75ms count=3
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
E/FrameEvents(26848): updateAcquireFence: Did not find frame.
 % flutter analyze
Analyzing bug...                                                        
No issues found! (ran in 2.4s)
[✓] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E772610a darwin-arm64, locale ja-JP)
    • Flutter version 3.10.0 on channel stable at /Users/******/flutter/flutter-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 84a1e904f4 (13 days ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/******/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Dev/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Dev/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Dev/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] Connected device (5 available)
    • SM A530F (mobile)           • 52001350ea4f6537          • android-arm64  • Android 9 (API 28)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 13 (API 33) (emulator)
    • YiPad (mobile)             • 00008030-0010390C14F0C02E • ios            • iOS 16.4.1 20E252
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 13.3.1 22E772610a darwin-arm64
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 113.0.5672.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Process finished with exit code 0
@huycozy huycozy added the in triage Issue currently being evaluated label May 23, 2023
@huycozy
Copy link
Collaborator

huycozy commented May 23, 2023

Hi @kmemo
The issue is caused by Align widget outside. If you remove it, other widgets can be displayed as normal.

Demo

Screenshot 2023-05-23 at 19 07 47

Also, since M3 will be enabled by default soon (flutter/flutter#127064), I would suggest you enable it from now for better support.

I will close the issue from here as solved. If you experience this issue with M3 in the future, please write in the comments and I will reopen it. Thank you!

@huycozy huycozy closed this as completed May 23, 2023
@huycozy huycozy added solved issue is closed as solved and removed in triage Issue currently being evaluated labels May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved issue is closed as solved
Projects
None yet
Development

No branches or pull requests

2 participants