Comments (3)
Hi @majornuts
For the issue to be workable, it needs to be reproducible with a completed and minimal reproducible code sample that doesnโt include 3rd party plugins or complex production code. Please provide such a sample. Thanks!
from flutter.
some how I cannot reproduce the exact error again, but the closes I've come is as follows.
import 'package:flutter/material.dart';
void main() {
runApp(const FloatingActionButtonExampleApp());
}
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FloatingActionButtonExample(),
);
}
}
class FloatingActionButtonExample extends StatefulWidget {
const FloatingActionButtonExample({super.key});
@override
State<FloatingActionButtonExample> createState() =>
_FloatingActionButtonExampleState();
}
class _FloatingActionButtonExampleState
extends State<FloatingActionButtonExample> {
// The FAB's foregroundColor, backgroundColor, and shape
static const List<(Color?, Color? background, ShapeBorder?)> customizations =
<(Color?, Color?, ShapeBorder?)>[
(null, null, null), // The FAB uses its default for null parameters.
(null, Colors.green, null),
(Colors.white, Colors.green, null),
(Colors.white, Colors.green, CircleBorder()),
];
int index = 0; // Selects the customization.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('FloatingActionButton Sample'),
),
body: const Center(child: Text('Press the button below!')),
floatingActionButton: buildFloatingActionButton(context),
);
}
}
buildFloatingActionButton(BuildContext context) {
Icon icon = const Icon(Icons.add, color: Colors.white);
return FloatingActionButton(
backgroundColor: const Color.fromRGBO(82, 170, 94, 1.0),
child: icon,
onPressed: () {
showBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
color: Colors.amber,
child: Row(
children:[
Text('Add member'),
]..addAll(MembersList.map((e) => ListTile(
onTap: () {
print(e);
},
title: Text(e),
)).toList()
),
));
});
});
}
List<String> MembersList = <String>['Bob', 'Alies'];
this produces the following error, witch is strange because it runs and crashs when the fab is clicked with the following:
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
No Scaffold widget found.
FloatingActionButtonExample widgets require a Scaffold widget ancestor.
The specific widget that could not find a Scaffold ancestor was: FloatingActionButtonExample
state: _FloatingActionButtonExampleState#af236
The ancestors of this widget were:
: MaterialApp
state: _MaterialAppState#86b49
: FloatingActionButtonExampleApp
...
Typically, the Scaffold widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree.
When the exception was thrown, this was the stack:
#0 debugCheckHasScaffold.<anonymous closure> (package:flutter/src/material/debug.dart:139:7)
#1 debugCheckHasScaffold (package:flutter/src/material/debug.dart:150:4)
#2 showBottomSheet (package:flutter/src/material/bottom_sheet.dart:1348:10)
#3 buildFloatingActionButton.<anonymous closure> (package:duty_planer/main3.dart:56:9)
#4 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1171:21)
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:344:24)
#6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
#7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
#8 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:242:7)
#9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:696:9)
#10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
#11 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
#12 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#13 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
#15 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:495:19)
#16 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:475:22)
#17 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:425:11)
#18 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:420:7)
#19 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:383:5)
#20 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:330:7)
#21 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:299:9)
#22 _invoke1 (dart:ui/hooks.dart:328:13)
#23 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:442:7)
#24 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
Handler: "onTap"
Recognizer: TapGestureRecognizer#fba88
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(748.5, 1205.9)
finalLocalPosition: Offset(20.5, 29.9)
button: 1
sent tap down
====================================================================================================
from flutter.
You can use a scaffoldKey
as this solution or use showModalBottomSheet
instead. Then you may hit BoxConstraints forces an infinite width
error, it's because you are putting too many widgets in a Row on bottom sheet builder (looks like it should be a Column instead). Try the updated sample code as a worked one:
Sample code
import 'package:flutter/material.dart';
void main() {
runApp(const FloatingActionButtonExampleApp());
}
class FloatingActionButtonExampleApp extends StatelessWidget {
const FloatingActionButtonExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FloatingActionButtonExample(),
);
}
}
class FloatingActionButtonExample extends StatefulWidget {
const FloatingActionButtonExample({super.key});
@override
State<FloatingActionButtonExample> createState() => _FloatingActionButtonExampleState();
}
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
class _FloatingActionButtonExampleState extends State<FloatingActionButtonExample> {
// The FAB's foregroundColor, backgroundColor, and shape
int index = 0; // Selects the customization.
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: const Text('FloatingActionButton Sample'),
),
body: const Center(child: Text('Press the button below!')),
floatingActionButton: buildFloatingActionButton(context),
);
}
}
buildFloatingActionButton(BuildContext context) {
Icon icon = const Icon(Icons.add, color: Colors.white);
return FloatingActionButton(
backgroundColor: const Color.fromRGBO(82, 170, 94, 1.0),
child: icon,
onPressed: () {
scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
return Container(
height: 200,
color: Colors.amber,
child: Column(
children: [
Text('Add member'),
]..addAll(MembersList.map((e) => ListTile(
onTap: () {
print(e);
},
title: Text(e),
)).toList()),
));
});
});
}
List<String> MembersList = <String>['Bob', 'Alies'];
Closing the issue because it is more suitable to ask on community channels. Please see flutter's community for resources and ask questions like this. You may also get some help if you post it on Stack Overflow and flutterhelp.
from flutter.
Related Issues (20)
- mac-27 lost external connection phone device. HOT 1
- [WASM] Flutter web throwing memory access out of bound error HOT 3
- [Impeller] STB usage in display list golden tests crash HOT 2
- [Impeller] disrespecting the ctm in mask blurs results in different results depending on dpi HOT 8
- Web FocusableActionDetector stops working after using Ctrl + F or Ctrl + P HOT 1
- Manual quarantine: flutter-devicelab-linux-36 HOT 1
- [flutter_tools] deprecate the --disable-dds flag
- Design Doc: DevTools Discoverability in VS Code
- Unable to compile an Android release due to task ':flutter:copyFlutterAssetsRelease' (add-to-app) HOT 2
- [go_router] Using ModalBottomSheetRoute for Nested Navigation within a BottomSheet[go_router] HOT 7
- Why is the space between the Flutter AppBar and the status bar significantly larger than the iOS system UI? HOT 3
- Conditionally bundling assets based on flavor make tests to fail HOT 7
- Canvas.drawImageNine incorrect edge case HOT 2
- ios app crashes with EXC_BAD_ACCESS (SIGSEGV) SEGV_NOOP HOT 1
- Chinese Pinyin input Enter event can not be detected HOT 1
- [tool_crash] FormatException HOT 1
- BorderRadius.all is not a constant, but it can be made constant HOT 2
- Simple code to break "dart fix" HOT 1
- `SliverLayoutDimensions` hash code doesn't include all properties. HOT 1
- Enhances intuitiveness of RawMagnifier's example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter.