Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ bellow you can see the currently available extensions in the latest version.
#### From the `MediaQuery`. Access properties right in the `context` instance. Available extensions:

* `context.mediaQuerySize`
* `context.widthPx`
* `context.heightPx`
* `context.widthPct`
* `context.heightPct`
* `context.orientation`
* `context.mediaQueryPadding`
* `context.alwaysUse24HourFormat`
Expand Down
8 changes: 8 additions & 0 deletions lib/src/build_context_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import 'package:flutter/material.dart';
extension MediaQueryExt on BuildContext {
Size get mediaQuerySize => MediaQuery.of(this).size;

double get widthPx => mediaQuerySize.width;

double get heightPx => mediaQuerySize.height;

double widthPct(int percentage) => (percentage * widthPx)/ 100;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 and 12 line not are formateds


double heightPct(int percentage) => (percentage * heightPx)/ 100;

EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding;

EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding;
Expand Down