flutter_test_gen 1.0.0
flutter_test_gen: ^1.0.0 copied to clipboard
A CLI tool to automatically generate Flutter and Dart unit tests. Generates structured test templates for classes and functions to speed up Flutter testing.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test_gen_example/services/counter_service.dart';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => const MaterialApp(home: CounterPage());
}
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
final CounterService viewModel = CounterService();
int counter = 0;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Counter App')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Counter Value', style: TextStyle(fontSize: 20)),
Text(
counter.toString(),
style:
const TextStyle(fontSize: 40, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
counter = viewModel.decrement(counter);
setState(() {});
},
child: const Text('-'),
),
const SizedBox(width: 10),
ElevatedButton(
onPressed: () {
counter = viewModel.reset();
setState(() {});
},
child: const Text('Reset'),
),
const SizedBox(width: 10),
ElevatedButton(
onPressed: () {
counter = viewModel.increment(counter);
setState(() {});
},
child: const Text('+'),
),
],
),
],
),
),
);
}