semantic_gen 0.2.4 copy "semantic_gen: ^0.2.4" to clipboard
semantic_gen: ^0.2.4 copied to clipboard

Compile-time helpers that expose Selenium-friendly semantics for Flutter Web and Widget tests.

example/lib/main.dart

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

void main() {
  runApp(const ExampleApp());
}

/// Demo application showcasing semantic_gen integration.
class ExampleApp extends StatelessWidget {
  /// Creates an [ExampleApp].
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'semantic_gen demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('semantic_gen demo'),
        ),
        body: const Padding(
          padding: EdgeInsets.all(24),
          child: LoginForm(),
        ),
      ),
    );
  }
}

/// Login form demonstrating auto-tagged widgets.
@AutoTag('auth')
class LoginForm extends StatelessWidget {
  /// Creates a [LoginForm].
  const LoginForm({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: const <Widget>[
        Text(
          'Sign in to your account',
          textAlign: TextAlign.center,
        ),
        SizedBox(height: 24),
        TextField(
          decoration: InputDecoration(labelText: 'Email'),
        ),
        SizedBox(height: 16),
        TextField(
          decoration: InputDecoration(labelText: 'Password'),
          obscureText: true,
        ),
        SizedBox(height: 24),
        LoginButton(),
      ],
    );
  }
}

/// Submit button that relies on a manual `testTag` wrapper.
@AutoTag('auth')
class LoginButton extends StatelessWidget {
  /// Creates a [LoginButton].
  const LoginButton({super.key});

  @override
  Widget build(BuildContext context) {
    return testTag(
      'auth:submit',
      ElevatedButton(
        onPressed: () {
          final scaffoldMessenger = ScaffoldMessenger.of(context);
          scaffoldMessenger.showSnackBar(
            const SnackBar(content: Text('Signing in...')),
          );
        },
        child: const Text('Sign in'),
      ),
      button: true,
      container: true,
    );
  }
}
0
likes
130
points
10
downloads

Documentation

Documentation
API reference

Publisher

verified publishercallahanwilliam.com

Weekly Downloads

Compile-time helpers that expose Selenium-friendly semantics for Flutter Web and Widget tests.

Repository (GitHub)
View/report issues

Topics

#testing #selenium #source-gen #accessibility #web

License

MIT (license)

Dependencies

analyzer, build, collection, dart_style, flutter, glob, meta, path, pub_semver, source_gen, yaml

More

Packages that depend on semantic_gen