Skip to content

Commit

Permalink
wrap string into text
Browse files Browse the repository at this point in the history
  • Loading branch information
aprosail committed Jun 28, 2024
2 parents 1d32ae4 + 226fc3b commit 946b4d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: publish

on:
push:
tags: ["[0-9]+.[0-9]+.[0-9]+*"]
push: {tags: ["[0-9]+.[0-9]+.[0-9]+*"]}

jobs:
# https://dart.dev/tools/pub/automated-publishing
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.1.2

- Wrap `Text` from `String`.
- Namespace cancel wrap (API change).
- Theme inherit interface definitions (experimental).

Expand Down
10 changes: 10 additions & 0 deletions lib/src/wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import 'package:flutter/widgets.dart';
Widget builder(Widget Function(BuildContext context) builder) =>
Builder(builder: builder);

extension WrapTextWidget on String {
/// Convert a string into text.
///
/// It's a syntax sugar as shortcut of [Text].
/// But it's strongly not recommended to use if you need better performance,
/// because it will disable the `const` decoration over the [Text],
/// that more steps will be done when rendering.
Text get asText => Text(this);
}

extension WrapMedia on Widget {
/// Chain style syntax sugar of wrapping [MediaQuery].
Widget media(MediaQueryData data) => MediaQuery(data: data, child: this);
Expand Down
29 changes: 23 additions & 6 deletions test/wrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:modifier/modifier.dart';

void main() {
testWidgets('enable text', (t) async {
await t.pumpWidget(
builder((context) => const Text('validation')
.ensureDirection(context)
.ensureMedia(context)),
);
testText();
}

void testText() {
group('text', () {
testWidgets('enable text', (t) async {
await t.pumpWidget(
builder((context) => const Text('validation')
.ensureDirection(context)
.ensureMedia(context)),
);
expect(find.text('validation'), findsOneWidget);
});

testWidgets('wrap text', (t) async {
await t.pumpWidget(
builder((context) => 'convert string into text'
.asText
.ensureDirection(context)
.ensureMedia(context)),
);
expect(find.text('convert string into text'), findsOneWidget);
});
});
}

0 comments on commit 946b4d0

Please sign in to comment.