auto_size_text 0.0.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 96

AutoSizeText #

Travis Version Runtime GitHub license

A widget that automatically resizes text to fit perfectly within its bounds.

Resources: #

Usage #

AutoSizeText behaves exactly like a Text. The only difference is that it resizes text to fit within its bounds.

AutoSizeText("The text to display",
  style: TextStyle(fontSize:20.0),
  maxlines: 2,
)

maxlines #

The maxlines parameter works like you are used to with the Text widget. If there is no maxlines parameter specified, the AutoSizeText only fits the text according to the available width and height.

AutoSizeText(
  "A really long String",
  style: TextStyle(fontSize: 30.0),
  maxLines: 2,
)

Sample above

minFontSize & maxFontSize

With minFontSize you can specify the smallest possible font size. If the text still not fits, it will be handled according to overflow. The default minFontSize is 12.0.

maxFontSize sets the largest passible font size. This is useful if the TextStyle inherits the font size and you want to constrain it.

AutoSizeText(
  "A really long String",
  style: TextStyle(fontSize: 30.0),
  minFontSize: 18.0,
  maxLines: 4,
  overflow: TextOverflow.ellipsis,
)

stepGranularity #

The AutoSizeText will try each font size, starting with TextStyle.fontSize until the text fits within its bounds.
stepGranularity specifies how much the font size is decreased each step. Usually, this value should not be below 1.0 for best performance.

AutoSizeText(
  "A really long String",
  style: TextStyle(fontSize: 40.0),
  minFontSize: 10.0,
  stepGranularity: 10.0,
  maxLines: 4,
  overflow: TextOverflow.ellipsis,
)

presetFontSizes #

If you want to allow only specific font sizes, you can set them with presetFontSizes. If presetFontSizes is set, minFontSize, maxFontSize and stepGranularity will be ignored.

AutoSizeText(
  "A really long String",
  presetFontSizes: [40.0, 20.0, 14.0],
  maxLines: 4,
)

Troubleshooting #

If AutoSizeText overflows or does not resize the text, you should check if it has constraint width / height.

Wrong code:

class MyPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        AutoSizeText("Here is a very long text, which should be resized",
          maxlines: 1,
        ),
      ],
    );
  }
}

Because Row does not constrain the width of its children, the text will overflow.

Correct code:

class MyPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Expanded( // Constrains AutoSizeText to the width of the Row
          child: AutoSizeText(
            "Here is a very long text, which should be resized",
            maxlines: 1,
          )
        ),
      ],
    );
  }
}

MIT License #

Copyright (c) 2018 Simon Leier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0.0.2 #

  • Fixed documentation
  • Added example

0.0.1 #

  • First Release

example/main.dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: SizedBox(
            width: 200,
            height: 140,
            child: AutoSizeText(
              "This string will be automatically resized to fit in two lines.",
              style: TextStyle(fontSize: 30.0),
              maxLines: 2,
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  auto_size_text: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:auto_size_text/auto_size_text.dart';
  
Version Uploaded Documentation Archive
2.0.1 Jun 7, 2019 Go to the documentation of auto_size_text 2.0.1 Download auto_size_text 2.0.1 archive
2.0.0+2 Jun 3, 2019 Go to the documentation of auto_size_text 2.0.0+2 Download auto_size_text 2.0.0+2 archive
2.0.0+1 Jun 3, 2019 Go to the documentation of auto_size_text 2.0.0+1 Download auto_size_text 2.0.0+1 archive
2.0.0 Jun 2, 2019 Go to the documentation of auto_size_text 2.0.0 Download auto_size_text 2.0.0 archive
1.1.2 Apr 5, 2019 Go to the documentation of auto_size_text 1.1.2 Download auto_size_text 1.1.2 archive
1.1.1 Mar 27, 2019 Go to the documentation of auto_size_text 1.1.1 Download auto_size_text 1.1.1 archive
1.1.0 Mar 13, 2019 Go to the documentation of auto_size_text 1.1.0 Download auto_size_text 1.1.0 archive
1.0.0 Feb 18, 2019 Go to the documentation of auto_size_text 1.0.0 Download auto_size_text 1.0.0 archive
0.3.0 Dec 6, 2018 Go to the documentation of auto_size_text 0.3.0 Download auto_size_text 0.3.0 archive
0.2.2 Nov 17, 2018 Go to the documentation of auto_size_text 0.2.2 Download auto_size_text 0.2.2 archive

All 18 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
85
Overall:
Weighted score of the above. [more]
96
Learn more about scoring.

We analyzed this package on Jun 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
grinder ^0.8.3