flutter / flutter/devtools

WidgetInspector finds wrong widget

Ouverte
#6,170 10 commentaires 4 réactions 1 personne assignée Réclamée par @CoderDake Voir sur GitHub
has reproducible steps P2 product-quality screen: inspector
Langage dominant
Dart
Étoiles
1.7k
Forks
404
Merge moyen
6 j 17 h
PR mergées (30 j)
18

Description

## Steps to reproduce

Run the following app:

sample app

```dart
import 'dart:ui' show window;

import 'package:flutter/material.dart';

void main() {
runApp(BugReport());
}

class BugReport extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Localizations(
locale: Locale('en', 'US'),
delegates: [
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
],
child: WidgetInspector(
selectButtonBuilder: (BuildContext context, VoidCallback onPressed) {
return FloatingActionButton(
child: const Icon(Icons.search),
onPressed: onPressed,
mini: true,
);
},
child: MediaQuery(
data: MediaQueryData.fromWindow(window),
child: Navigator(
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute(
settings: settings,
builder: (BuildContext context) {
return DefaultTextStyle(
style: TextStyle(color: Colors.black),
child: Home(),
);
},
);
},
),
),
),
);
}
}

class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
DecoratedBox(
decoration: BoxDecoration(color: Color(0xffc8c8bb)),
child: Padding(
padding: EdgeInsets.all(8),
child: Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: 60,
child: GestureDetector(
onTap: () => _openModalDialog(context),
child: Container(
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(border: Border.all()),
child: Text('Open Modal Dialog'),
),
),
),
),
),
),
Expanded(
child: ColoredBox(color: Colors.white),
),
],
);
}
}

Future _openModalDialog(BuildContext context) {
showGeneralDialog(
context: context,
barrierDismissible: false,
barrierLabel: 'Dismiss',
barrierColor: const Color(0x80000000),
pageBuilder: (
BuildContext context,
Animation animation,
Animation secondaryAnimation,
) {
return DefaultTextStyle(
style: TextStyle(color: Colors.black),
child: Align(
alignment: Alignment.topCenter,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(color: Color(0xff999999)),
color: Color(0xfff7f5ee),
),
child: Padding(
padding: EdgeInsets.all(8),
child: SizedBox(
width: 460,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
height: 200,
child: Container(color: Colors.cyan),
),
SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
GestureDetector(
onTap: () => Navigator.of(context).pop(),
child: Container(
width: 66,
height: 22,
alignment: Alignment.center,
decoration: BoxDecoration(border: Border.all()),
child: Text('OK'),
),
),
],
),
],
),
),
),
),
),
);
},
);
}
```

Then:

1. Click "Open Modal Dialog" (this will activate the widget inspector rather than launch the dialog)
1. Click "Open Modal Dialog" _again_ to open the modal dialog
1. Click the magnifying glass select button in the lower left of the app
1. Click the upper part of the cyan box in the modal dialog -- the part that is vertically aligned with the "Open Modal Dialog" button.

## Expected behavior

You expect the widget inspector to detect and highlight the cyan box (the `Container` or its `SizedBox` parent).

## Actual behavior

The widget inspector detects and highlights the `Align` widget that houses the "Open Modal Dialog" box. This widget is (a) under a modal barrier and cannot receive input events, and (b) painted over and is obscured by the cyan box in the modal dialog -- and so the widget inspector should not be able to select it.

![ezgif-7-543401d178cc](https://user-images.githubusercontent.com/15253456/89823154-da2e2c80-db05-11ea-8cd2-87d2b9701b55.gif)

## Other info

I have variants of this happen quite often, and it completely removes the utility of the widget inspector when it happens, so marking as P3.

Version info

```
[✓] Flutter (Channel master, 1.21.0-7.0.pre, on Mac OS X 10.15.3 19D76, locale en-US)
• Flutter version 1.21.0-7.0.pre at /Users/tvolkert/project/flutter/flutter
• Framework revision d261f1ef58 (8 days ago), 2020-08-03 00:59:36 -0400
• Engine revision 083282e33b
• Dart version 2.10.0 (build 2.10.0-2.0.dev 365525432a)


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/tvolkert/Library/Android/sdk
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
• Xcode at /Applications/Xcode_11.6.app/Contents/Developer
• Xcode 11.6, Build version 11E708
• CocoaPods version 1.9.2

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

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.0.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.3 19D76
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.105
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.