31.64 Flutter Style Imports

20230810

Maintain a consistent rule for the ordering of the imports, unless there is any specific purpose for having an import earlier or later. Generally, sort them into groups, and within the groups sort them alphabetically. Maintain that across all the dart source files.

If importing a single class or function, then use the show keyword as self documenting why the package is required.

Begin with the dart then the flutter packages, then special case packages (e.g., window_manager) and finally your application packages.

Encouraged

import 'dart:io' show Platform;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';

import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:window_manager/window_manager.dart';

import 'package:myapp/constants/app.dart';
import 'package:myapp/pages/home.dart';
import 'package:myapp/pages/settings_page.dart';
import 'package:myapp/widgets/grid_cards.dart';
import 'package:myapp/widgets/markdown_file.dart';
import 'package:myapp/widgets/multiple_split_view.dart';

Resources



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0