[Bug]: Doesn't show the body of popover
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
There were existing bugs on this, but none were from the body of the scaffold. This is happening even in the body of a scaffold. When, I am clicking the button, I just see the app becoming grayish and that's all. No popup menu. This happens with my code only. How ever I try. Even if I just copy paste the code from the example folder. But, when I run from the example folder everything is fine.
Expected Behavior
There should be a popup.
What operating system are you seeing the problem on?
Linux, Android
Relevant log output
import 'package:flutter/material.dart';
import 'package:popover/popover.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 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 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: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
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
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(title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Center(
// 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.
child: IconButton(
onPressed: () {
showPopover(
backgroundColor: Colors.red,
height: 100,
width: 100,
context: context,
bodyBuilder: (context) => const Dialog(
backgroundColor: Colors.red,
),
);
},
icon: const Icon(Icons.add),
),
),
),
);
}
}
Anything else?
My pubspec.yaml file
name: test
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.2.3 <4.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
popover: ^0.2.8+2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
And my flutter doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.3, on Ubuntu 23.10 6.5.0-13-generic, locale
en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/linux#android-setup for
more details.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.1)
[✓] Connected device (2 available)
[✓] Network resources
! Doctor found issues in 1 category.
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
@soumyaDghosh Thanks for submitting an issue. Feel free to create a PR if you think this is a bug to fix it.
I have no idea why is this bug even happening. I am kinda newbiew. So, atleast guide me on the debugging. Are you atleast able to reproduce it?
@soumyaDghosh I don't have a Linux machine now. On the macOS example, the project works as expected for all targets. Can you run it on your machine, please? Could you make sure that you're on a stable channel?
As I said in my issue, the example works but not after I copy paste the code to my project. Kindly check if you can run this given test code.
I am facing the same issue @soumyaDghosh , did you fix this?
I am facing the same issue @soumyaDghosh , did you fix this?
Nah.. I just left this for now
@minikin fix this bug.
I understand this bug can be frustrating. Unfortunately, I can't commit to a fix due to limited resources or other priorities. However, I encourage you or others to contribute a fix via a pull request.
I think the problem is that you are using the context of the build method of your home page. Try wrapping your button in a stateless widget and using the context of that widget. @soumyaDghosh
I think the problem is that you are using the context of the build method of your home page. Try wrapping your button in a stateless widget and using the context of that widget. @soumyaDghosh
Thank you... I'll get it a look
I think the problem is that you are using the context of the build method of your home page. Try wrapping your button in a stateless widget and using the context of that widget. @soumyaDghosh
Thanks, this solves the issue perfectly.
I think the problem is that you are using the context of the build method of your home page. Try wrapping your button in a stateless widget and using the context of that widget. @soumyaDghosh
This solution is working flawlessly, thank you.