Skip to content

Dartify media queries #9233

Open
Open
@DartBot

Description

This issue was originally filed by @seaneagan


Could replace:

MediaQueryList
Window.matchMedia

with:

class MediaQuery {
  // parses/validates query
  MediaQuery(this._query) native;
  
  toString() => _query;
  final String _query;
}

class Window {
  // ...
  Stream<bool> onMediaMatchChange(MediaQuery mq);
  bool matchesMedia(MediaQuery mq);
}

If the Stream emitted an event corresponding to initial state at the time the Stream was created, then maybe the synchronous matchesMedia could be removed, and could just use Stream.first.then. Can checking a media query cause a layout ?

Example:

// parse/validate media query
var mq = new MediaQuery("(orientation: portrait)");

// initialize
setPortraitMode(window.matchesMedia(mq));

// handle updates
window.onMediaMatchChange(mq).listen(setPortraitMode);

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-webUse area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.library-htmltype-enhancementA request for a change that isn't a bugweb-librariesIssues impacting dart:html, etc., libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions