Skip to content

Commit

Permalink
fix export at root
Browse files Browse the repository at this point in the history
  • Loading branch information
aprosail committed Jun 26, 2024
1 parent f37ba8a commit 21ff817
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions lib/src/wrap.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/widgets.dart';

/// An encapsulation of [Builder], also used as an alias.
Widget builder(Widget Function(BuildContext context) builder) =>
Builder(builder: builder);

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

/// Ensure that the inner widget can get [MediaQueryData] from the context.
/// If there's no available [MediaQueryData], it will get from the [View].
Widget ensureMedia(BuildContext context) {
final media = MediaQuery.maybeOf(context);
return media == null
? wrapMedia(MediaQueryData.fromView(View.of(context)))
: this;
}
}

extension WrapDirection on Widget {
Widget wrapDirection(TextDirection direction) =>
Directionality(textDirection: direction, child: this);

/// Ensure that the inner widget can get [TextDirection] from the context.
/// You can specify the [defaultValue]
/// if you prefer [TextDirection.rtl] as default.
Widget ensureDirection(
BuildContext context, {
TextDirection defaultValue = TextDirection.ltr,
}) {
final direction = Directionality.maybeOf(context);
return direction == null ? wrapDirection(defaultValue) : this;
}
}
2 changes: 1 addition & 1 deletion test/wrap_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:modifier/src/wrap.dart';
import 'package:modifier/modifier.dart';

void main() {
testWidgets('enable text', (t) async {
Expand Down

0 comments on commit 21ff817

Please sign in to comment.