flutter_design_guard 0.1.0 copy "flutter_design_guard: ^0.1.0" to clipboard
flutter_design_guard: ^0.1.0 copied to clipboard

A modern Dart analysis server plugin for enforcing Flutter design-system rules in Flutter projects.

Flutter Design Guard #

A Dart analyzer plugin that helps Flutter teams enforce design-system components by preventing direct use of native text fields.

The first stable release provides the avoid_native_text_field diagnostic, which detects direct usage of Flutter's TextField and TextFormField.

Requirements #

  • Dart SDK 3.11 or newer.
  • A Flutter project using the modern Dart analyzer plugin system.
  • The plugin must be configured in the root analysis_options.yaml file.

Installation #

Add the plugin to the top-level plugins section of your project's root analysis_options.yaml file:

plugins:
  flutter_design_guard:
    version: ^0.1.0
    diagnostics:
      avoid_native_text_field: true

Do not place plugins under the analyzer section.

You don't need to add flutter_design_guard to your application's pubspec.yaml. Analyzer plugins are resolved separately by the Dart Analysis Server.

After adding or changing the plugin configuration, restart the Dart Analysis Server.

Visual Studio Code #

Open the command palette and run:

Dart: Restart Analysis Server

Android Studio or IntelliJ IDEA #

Use:

File > Invalidate Caches / Restart

You can also restart the IDE.

Usage #

After enabling the diagnostic, run:

flutter analyze

You can also use:

dart analyze

The diagnostic also appears directly in supported editors.

Available diagnostics #

avoid_native_text_field #

Prevents direct usage of Flutter's native TextField and TextFormField widgets.

This helps projects consistently use their own design-system field component.

Invalid

import 'package:flutter/material.dart';

class LoginForm extends StatelessWidget {
  const LoginForm({super.key});

  @override
  Widget build(BuildContext context) {
    return const TextField();
  }
}
import 'package:flutter/material.dart';

class ProfileForm extends StatelessWidget {
  const ProfileForm({super.key});

  @override
  Widget build(BuildContext context) {
    return const TextFormField();
  }
}

The analyzer reports:

Do not use TextField directly. Use your design-system text field instead.

Valid

Use the text-field component provided by your application or design system:

import 'package:flutter/material.dart';

class AppTextField extends StatelessWidget {
  const AppTextField({super.key});

  @override
  Widget build(BuildContext context) {
    return const SizedBox();
  }
}
class LoginForm extends StatelessWidget {
  const LoginForm({super.key});

  @override
  Widget build(BuildContext context) {
    return const AppTextField();
  }
}

Disabling the diagnostic #

To disable the rule while keeping the plugin installed:

plugins:
  flutter_design_guard:
    version: ^0.1.0
    diagnostics:
      avoid_native_text_field: false

Suppressing a diagnostic #

Suppress one occurrence:

// ignore: flutter_design_guard/avoid_native_text_field
final field = TextField();

Suppress the diagnostic for an entire file:

// ignore_for_file: flutter_design_guard/avoid_native_text_field

Suppress

4
likes
0
points
336
downloads

Publisher

unverified uploader

Weekly Downloads

A modern Dart analysis server plugin for enforcing Flutter design-system rules in Flutter projects.

Repository (GitHub)
View/report issues

Topics

#analyzer #flutter #lints #static-analysis #code-quality

License

unknown (license)

Dependencies

analysis_server_plugin, analyzer, analyzer_plugin, yaml

More

Packages that depend on flutter_design_guard