dedent 0.0.2
dedent: ^0.0.2

Flutter Android iOS web

Remove any common leading whitespace from every line in text.

dedent #

Dedent - Remove any common leading whitespace from every line in text. Ported from Python.

Install #

Add

dependencies:
  dedent: any

to your pubspec.yaml then run the usual flutter pub get or just pub get for a pure dart project.

Usage #

import 'package:dedent/dedent.dart';

It's quite handy to strip leading spaces from multi-line text. Flutter code often involves deeply nested indented code, so any multiline text will end up containing leading spaces or tabs - which may affect your layout!

FittedBox(
  child: Text(dedent('''
    Not really possible to access another widget, or rather, another
    widget's state in order to change it. You really need to create
    a model and have the model change cause the change.
  ''')),
)

dedent() removes any common leading whitespace from every line in text. This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.

more specifically

    var text = '''
        def foo():
            while 1:
                return foo
        ''';

    var _expect = '''
def foo():
    while 1:
        return foo
''';

    expect(_expect, equals(dedent(text)));

Note that dedent() is ported from the long standing and reliable Python textwrap.dedent algorithm, complete with the original unit tests, so you know its good. πŸ‘

Tests #

This project is a direct translation of the Python textwrap.dedent algorithm.

Tests are also ported from Python.

flutter test

Contributing #

This section is only applicable if you want to fiddle with the dedent source code

When checking out from https://github.com/abulka/flutter-dedent ensure you specify dedent as a target so that the package directory is named dedent not flutter-dedent. Viz.

git clone git@github.com:abulka/flutter-dedent.git dedent

If you have checked out the dedent project locally and prefer your other Dart/Flutter projects to refer to this local copy instead of to the official version of dedent on pub.dev, simply adjust your pubspec.yaml:

dependencies:
  dedent:
    path: ../dedent

which assumes a directory structure where you are referring to the local dedent project from a sibling project e.g. called flutter_proj1 like this:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Development Directoryβ”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚                      
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”œβ”€β–Άβ”‚  flutter_proj1   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚                      
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
└─▢│      dedent      β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Thanks to the Python community for this algorithm.

0
likes
90
pub points
0%
popularity

Remove any common leading whitespace from every line in text.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

abulka@gmail.com

License

GPL (LICENSE)

Dependencies

quiver

More

Packages that depend on dedent