Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
format tidy code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aprosail committed May 20, 2024
1 parent 916be0a commit 0f34d0f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- **Incompatible**: API about `ReContext` changed.
- Use `builder` instead of `ReContext`, which is conciser.
- Optimize tests and tidy code structure.

## 0.6.0

Expand Down
17 changes: 17 additions & 0 deletions lib/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ extension WrapContext on Widget {
/// An encapsulation of [Builder], which makes it conciser.
Widget builder(Widget Function(BuildContext context) builder) =>
Builder(builder: builder);

extension WrapMedia on Widget {
Widget wrapMedia(MediaQueryData data) => MediaQuery(data: data, child: this);

/// Ensure the widget is wrapped by a [MediaQuery] ancestor.
///
/// Provide environment for [MediaQuery.of] that many widgets need,
/// including the [Text] widget. Without such ancestor,
/// once displaying a [Text],
/// it will throw exceptions.
Widget ensureMedia(BuildContext context) {
final media = MediaQuery.maybeOf(context);
return media == null
? wrapMedia(MediaQueryData.fromView(View.of(context)))
: this;
}
}
18 changes: 0 additions & 18 deletions lib/src/media.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/src/text.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';

import 'media.dart';
import 'context.dart';

extension WrapDirectionality on Widget {
Widget wrapDirectionality(TextDirection direction) => Directionality(
Expand Down
1 change: 0 additions & 1 deletion lib/wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export 'src/decorate.dart';
export 'src/handler.dart';
export 'src/inherit.dart';
export 'src/list.dart';
export 'src/media.dart';
export 'src/size.dart';
export 'src/text.dart';

0 comments on commit 0f34d0f

Please sign in to comment.