Skip to content

Commit

Permalink
fix textAlign argument
Browse files Browse the repository at this point in the history
textAlign이 적용되지 않는 문제 해결
  • Loading branch information
aqoong committed Jun 4, 2024
1 parent e92723b commit bee588a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,17 @@ pre-release version
### features

* Automatically adjust the fontSize to a size that does not exceed the size of the parent Widget.
* Supports rewriting that prevents the word in the string from breaking.
* Supports rewriting that prevents the word in the string from breaking.

## 0.0.3

pre-release version

### changes

* Resolving the issue where the textAlign option is not applied.

### planning

* Processing strings that contain newline characters.
* Compatibility testing for lower Flutter versions
15 changes: 11 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class _MyAppState extends State<MyApp> {
color: Colors.black,
fontWeight: FontWeight.w800,
height: 1.2,
backgroundColor: Colors.blue,
);

return MaterialApp(
Expand All @@ -38,12 +37,20 @@ class _MyAppState extends State<MyApp> {
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
borderContainer(const Text(text, style: style, maxLines: 3,)),
borderContainer(const SizeTailoredText(
const SizeTailoredText(
text: text,
textStyle: style,
maxLines: 5,
textAlign: TextAlign.start,
),
borderContainer(const Text(text, style: style)),
borderContainer(const SizeTailoredText(
text: text,
textStyle: style,
maxLines: 3,
textAlign: TextAlign.center,
))
],
),
Expand All @@ -54,7 +61,7 @@ class _MyAppState extends State<MyApp> {

Widget borderContainer(Widget child) => Container(
width: double.infinity,
height: 400,
height: 200,
decoration: const BoxDecoration(
border: Border.fromBorderSide(BorderSide(color: Colors.red))),
child: child,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.0.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down
47 changes: 32 additions & 15 deletions lib/size_tailored_text.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2024. AQoong(cooldnjsdn@gmail.com) All rights reserved.
*/
library size_tailored_text;

import 'package:flutter/material.dart';

Expand All @@ -9,36 +10,34 @@ class SizeTailoredText extends StatefulWidget {
final double calRefSize; //사이즈 조정 수치
final TextStyle textStyle;

final int? maxLines;
final int maxLines;
final Locale? locale;
final TextOverflow? overflow;
final Color? selectionColor;
final String? semanticsLabel;
final bool? softWrap;
final bool softWrap;
final StrutStyle? strutStyle;
final TextAlign? textAlign;
final TextDirection? textDirection;
final TextScaler? textScaler;
final TextScaler textScaler;
final TextHeightBehavior? textHeightBehavior;
final TextWidthBasis? textWidthBasis;
final TextWidthBasis textWidthBasis;

const SizeTailoredText({
super.key,
required this.text,
required this.textStyle,
this.calRefSize = 0.5,
this.maxLines,
this.maxLines = 1,
this.textDirection,
this.textAlign,
this.semanticsLabel,
this.selectionColor,
this.overflow,
this.locale,
this.softWrap,
this.softWrap = true,
this.strutStyle,
this.textHeightBehavior,
this.textScaler,
this.textWidthBasis,
this.textScaler = TextScaler.noScaling,
this.textWidthBasis = TextWidthBasis.parent,
});

@override
Expand All @@ -48,6 +47,16 @@ class SizeTailoredText extends StatefulWidget {
class _SizeTailoredTextState extends State<SizeTailoredText> {
double _changedFontSize = 0;

@override
void initState() {
super.initState();
}

@override
void didUpdateWidget(SizeTailoredText oldWidget) {
super.didUpdateWidget(oldWidget);
}

@override
Widget build(BuildContext context) {
_changedFontSize = widget.textStyle.fontSize ?? 14;
Expand All @@ -70,9 +79,8 @@ class _SizeTailoredTextState extends State<SizeTailoredText> {
break;
}
}
fontSize -= widget.calRefSize;

_changedFontSize = fontSize;

return RichText(
text: TextSpan(
children: _buildTextSpans(
Expand All @@ -81,6 +89,15 @@ class _SizeTailoredTextState extends State<SizeTailoredText> {
constraints.maxWidth,
),
),
textAlign: widget.textAlign ?? TextAlign.start,
textHeightBehavior: widget.textHeightBehavior,
strutStyle: widget.strutStyle,
softWrap: widget.softWrap,
textWidthBasis: widget.textWidthBasis,
textDirection: widget.textDirection,
selectionColor: widget.selectionColor,
locale: widget.locale,
maxLines: widget.maxLines,
);
},
);
Expand All @@ -94,14 +111,14 @@ class _SizeTailoredTextState extends State<SizeTailoredText> {

TextPainter _commonTextPainter() => TextPainter(
text: TextSpan(text: widget.text, style: _commonTextStyle()),
maxLines: widget.maxLines ?? 1,
maxLines: widget.maxLines,
textDirection: widget.textDirection ?? TextDirection.ltr,
textScaler: widget.textScaler ?? TextScaler.noScaling,
textScaler: widget.textScaler,
locale: widget.locale,
strutStyle: widget.strutStyle,
textAlign: widget.textAlign ?? TextAlign.start,
textHeightBehavior: widget.textHeightBehavior,
textWidthBasis: widget.textWidthBasis ?? TextWidthBasis.parent,
textWidthBasis: widget.textWidthBasis,
);

List<TextSpan> _buildTextSpans(String text, TextStyle style, double maxWidth) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: size_tailored_text
description: "Size the text to the size of the parent widget."
version: 0.0.2
version: 0.0.3
homepage: https://github.com/aqoong/size_tailored_text

environment:
Expand Down

0 comments on commit bee588a

Please sign in to comment.