gen_expects 0.2.2 copy "gen_expects: ^0.2.2" to clipboard
gen_expects: ^0.2.2 copied to clipboard

Code generator that walks the widget tree of the test app and outputs expect statements for widget tests.

example/lib/main.dart

import 'package:flutter/material.dart';

part 'main.keys.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(
        title: 'example',
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        key: MainKeys.appBar,
        title: Text(widget.title),
      ),
      body: Center(
        key: const ValueKey(MyClassKeys.center),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: Fab(
        onPressed: _incrementCounter,
      ),
    );
  }
}

class Fab extends StatelessWidget {
  const Fab({
    this.onPressed,
    super.key,
  });

  final VoidCallback? onPressed;

  @override
  Widget build(BuildContext context) {
    return FloatingActionButton(
      onPressed: onPressed,
      tooltip: 'Increment',
      child: const Icon(Icons.add),
    );
  }
}

enum MyClassKeys {
  center;
}
5
likes
140
pub points
66%
popularity

Publisher

verified publisherrichardcoutts.com

Code generator that walks the widget tree of the test app and outputs expect statements for widget tests.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_test

More

Packages that depend on gen_expects