exceptionsAreBad
exceptionsAreBad

Reputation: 653

How to get flutter windows desktop users screen width at runtime

So, normally I can get screen size by using MediaQuery.of(context).size, however I don't have access to context at runtime. Is there any package or API I can tap into to accomplish this ?

EDIT: Accepted @smorgan answer. Adding the pubspec.yaml entry with small use case for others, so they don't have to go digging.

**Noting this will eventually be removed and added into flutter core functionality (hopefully).

Also the ref field is the commit hash of current branch as of 12/15/21

pubspec.yaml entry:

window_size:
git:
  url: git://github.com/google/flutter-desktop-embedding.git
  path: plugins/window_size
  ref: 03d957e8b5c99fc83cd4a781031b154ab3de8753

Getting Screen Size

var screenSize = await getCurrentScreen();
print(screenSize?.frame.size);

Upvotes: 1

Views: 995

Answers (2)

smorgan
smorgan

Reputation: 21599

The window_size plugin will let you get the current screen size, or a list of all screens and their sizes.

Upvotes: 1

Stijn2210
Stijn2210

Reputation: 884

This is what I use for my flutter windows app:

https://pub.dev/packages/desktop_window

Upvotes: 0

Related Questions