Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add text align property to Text #95

Merged
merged 2 commits into from
May 4, 2022
Merged
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
2 changes: 2 additions & 0 deletions examples/flutter_playground/lib/left_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LeftMenu extends StatelessWidget {
static const stackExample = "stackExample";
static const overlayEntryExample = "overlayEntryExample";
static const sliderExample = "sliderExample";
static const textExample = "textExample";

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -50,6 +51,7 @@ class LeftMenu extends StatelessWidget {
createMenu(context, 'overlayEntry Example', overlayEntryExample),
createMenu(context, 'OverlayEntry Examples', overlayEntryExample),
createMenu(context, 'Slider Examples', sliderExample),
createMenu(context, 'Text Example', textExample),
],
);
}
Expand Down
3 changes: 3 additions & 0 deletions examples/flutter_playground/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'pages/flex_test.dart';
import 'pages/overlay_entry_example.dart';
import 'pages/slider_example.dart';
import 'pages/stack_example.dart';
import 'pages/text_example.dart';
import 'pages/toggle_example.dart';
import 'pages/button_example.dart';
import 'pages/checkbox_example.dart';
Expand Down Expand Up @@ -93,6 +94,8 @@ class _MyAppState extends State<MyApp> {
return const OverlayEntryExample();
case LeftMenu.sliderExample:
return const SliderExample();
case LeftMenu.textExample:
return const TextExample();
}
return const Text("N/A");
}
Expand Down
44 changes: 44 additions & 0 deletions examples/flutter_playground/lib/pages/text_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:lenra_components/component/lenra_text.dart';
import 'package:lenra_components/layout/lenra_flex.dart';
import 'package:lenra_components/lenra_components.dart';

class TextExample extends StatefulWidget {
const TextExample({Key? key}) : super(key: key);

@override
State<StatefulWidget> createState() {
return _TextExampleState();
}
}

class _TextExampleState extends State<TextExample> {
@override
Widget build(BuildContext context) {
return Center(
child: LenraFlex(
direction: Axis.vertical,
spacing: 4,
children: [
LenraText(text: "Basic"),
Container(
decoration: BoxDecoration(border: Border.all()),
width: 60,
child: LenraText(
text: "This is a centered text.",
textAlign: TextAlign.center,
),
),
Container(
decoration: BoxDecoration(border: Border.all()),
width: 100,
child: LenraText(
text: "This is a justified text. This is a justified text.",
textAlign: TextAlign.justify,
),
),
],
),
);
}
}
3 changes: 3 additions & 0 deletions lib/component/lenra_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class LenraText extends StatelessWidget {
final Locale? locale;
final String? semanticsLabel;
final bool? spellOut;
final TextAlign? textAlign;

const LenraText({
Key? key,
Expand All @@ -16,6 +17,7 @@ class LenraText extends StatelessWidget {
this.locale,
this.semanticsLabel,
this.spellOut,
this.textAlign,
}) : super(key: key);

TextSpan _toTextSpan(LenraText text) {
Expand All @@ -40,6 +42,7 @@ class LenraText extends StatelessWidget {
semanticsLabel: semanticsLabel,
spellOut: spellOut,
),
textAlign: textAlign,
);
}
}
2 changes: 2 additions & 0 deletions test/component/lenra_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ void main() {
style: style,
semanticsLabel: "bar",
locale: const Locale('fr', 'FR'),
textAlign: TextAlign.center,
);

expect(lenraText.text, "foo");
expect(lenraText.style, style);
expect(lenraText.spellOut, false);
expect(lenraText.semanticsLabel, "bar");
expect(lenraText.locale, const Locale('fr', 'FR'));
expect(lenraText.textAlign, TextAlign.center);
});

testWidgets('Test LenraText children', (WidgetTester tester) async {
Expand Down