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

Using Colors.black as a primarySwatch causes an opaque error #1650

Closed
johnpryan opened this issue Oct 14, 2020 · 7 comments
Closed

Using Colors.black as a primarySwatch causes an opaque error #1650

johnpryan opened this issue Oct 14, 2020 · 7 comments
Labels
area-error-messaging P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) type-ux A user experience or user interface related issue
Milestone

Comments

@johnpryan
Copy link
Contributor

Using Colors.black as a primarySwatch causes an opaque error

  1. open https://dartpad.dev/b6409e10de32b280b8938aa75364fa7b
  2. change primarySwatch from Colors.blue to Colors.black
  3. click Run
  4. Observe the app stops working without analysis errors or console output

Here's the error in the javascript console:

Uncaught Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter/packages/flutter/lib/src/widgets/framework.dart:2687:20
_debugCurrentBuildTarget == context
is not true
    at Object.throw_ [as throw] (storage.googleapis.com/compilation_artifacts/2.10.0/dart_sdk.js:4328)
    at Object.assertFailed (storage.googleapis.com/compilation_artifacts/2.10.0/dart_sdk.js:4275)
    at storage.googleapis.com/compilation_artifacts/2.10.0/flutter_web.js:318195
    at framework.BuildOwner.new.buildScope (storage.googleapis.com/compilation_artifacts/2.10.0/flutter_web.js:318199)
    at RenderObjectToWidgetAdapter.new.attachToRenderTree (storage.googleapis.com/compilation_artifacts/2.10.0/flutter_web.js:306959)
    at binding$.WidgetsFlutterBinding.new.attachRootWidget (storage.googleapis.com/compilation_artifacts/2.10.0/flutter_web.js:306827)
    at storage.googleapis.com/compilation_artifacts/2.10.0/flutter_web.js:306822
    at internalCallback (storage.googleapis.com/compilation_artifacts/2.10.0/dart_sdk.js:23761)
@johnpryan
Copy link
Contributor Author

Related to #1649

@RedBrogdon RedBrogdon added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on type-ux A user experience or user interface related issue labels Oct 22, 2020
@RedBrogdon RedBrogdon added this to the Backlog milestone Oct 22, 2020
@domesticmouse
Copy link
Member

domesticmouse commented Nov 17, 2020

I'm curious why this code doesn't throw a type error during analysis. primarySwatch is typed as MaterialColor and Colors.black is typed as a Color.

@domesticmouse
Copy link
Member

As of Flutter 1.25 this is much less of an issue. The analyzer issues an error.

Screen Shot 2021-01-07 at 8 50 27 pm

@domesticmouse domesticmouse added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Jan 7, 2021
@johnpryan
Copy link
Contributor Author

Type checking FTW. Now I'm thinking that the problem is with printing assertion failures:

import 'package:flutter/material.dart';
void main() {
  assert(1 == 2);
}

This prints an error in the javascript console, but not the DartPad console.

@RedBrogdon
Copy link
Contributor

One of the areas of tech debt we really need to address is error reporting in general. If this can be bundled into some of the DartPad work we've already talked about in the next few months (by you or anyone else), it'd be worth the investment.

@johnpryan
Copy link
Contributor Author

Another case where this shows up:

import 'package:flutter/material.dart';

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

class ListViewApp extends StatelessWidget {
  static const itemCount = 10;
  const ListViewApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: ListView.builder(
          // itemCount: itemCount, // uncomment to fix!
          itemBuilder: (context, idx) {
            assert(idx < itemCount);
            return ListTile(
              title: Text('$idx'),
            );
          },
        ),
      ),
    );
  }
}

We should be displaying something more user-friendly instead of crashing. Running locally shows a red widget of death:

Screen Shot 2021-05-18 at 5 06 13 PM

but in DartPad we get a stack trace in the JavaScript console and Script error. in the DartPad console:

Uncaught Error: Assertion failed: file:///Users/brettmorgan/Documents/GitHub/dart-services/flutter-sdk/packages/flutter/lib/src/rendering/object.dart:1532:12
_debugCanPerformMutations
is not true
    at Object.throw_ [as throw] (dart_sdk.js:5037)
    at Object.assertFailed (dart_sdk.js:4976)
    at view.RenderView.new.markNeedsLayout (flutter_web.js:195881)
    at view.RenderView.new.set configuration [as configuration] (flutter_web.js:442310)
    at binding$.WidgetsFlutterBinding.new.handleMetricsChanged (flutter_web.js:327613)
    at binding$.WidgetsFlutterBinding.new.handleMetricsChanged (flutter_web.js:325887)
    at Object.invoke (dart_sdk.js:175219)
    at _engine.EnginePlatformDispatcher.__.invokeOnMetricsChanged (dart_sdk.js:156971)
    at _engine.DomRenderer.new.[_metricsDidChange] (dart_sdk.js:140844)
    at Object._checkAndCall (dart_sdk.js:5242)
    at Object.dcall (dart_sdk.js:5247)
    at VisualViewport.<anonymous> (dart_sdk.js:100617)

@johnpryan
Copy link
Contributor Author

johnpryan commented Jul 22, 2021

Tracking this issue here: #1966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-error-messaging P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) type-ux A user experience or user interface related issue
Projects
None yet
Development

No branches or pull requests

3 participants