2

I wonder how to behave with long strings to make code clean. Code example:

Text(
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
)

Is it good approach to have such a string in one line of code? It is contrary to lines_longer_than_80_chars lint. Or it is better to split it into mulitple lines like:

Text(
  'Lorem ipsum dolor sit amet, consectetur adipiscing '
  'elit, sed do eiusmod tempor incididunt ut labore et '
  'dolore magna aliqua. Ut enim ad minim veniam, quis '
  'nostrud exercitation ullamco laboris nisi ut '
  'aliquip ex ea commodo consequat. Duis aute irure '
  'reprehenderit in voluptate velit esse cillum dolore '
  'eu fugiat nulla pariatur. Excepteur sint occaecat '
  'cupidatat non proident, sunt in culpa qui officia '
  'deserunt mollit anim id est laborum.',
)

Such a splitting is time-consuming, is there any way to make it automatically, with formatter for example?

Maybe there is any better approach?

1 Answer 1

2

If your string is that large, have you considered using assets?

flutter:
  assets:
    - lipsum.txt
import 'package:flutter/services.dart' show rootBundle;

Future<String> loadAsset() async {
  return await rootBundle.loadString('assets/lipsum.txt');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It's time-consuming solution, nevertheless for large strings great approach to keep code clean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.