mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 22:38:42 +00:00
## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/wiki/Chat [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com> Co-authored-by: David Iglesias <ditman@gmail.com> Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com> Co-authored-by: David Iglesias <ditman@gmail.com>
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class CounterDemo extends StatefulWidget {
|
|
final ValueNotifier<int> counter;
|
|
|
|
const CounterDemo({
|
|
super.key,
|
|
required this.counter,
|
|
});
|
|
|
|
@override
|
|
State<CounterDemo> createState() => _CounterDemoState();
|
|
}
|
|
|
|
class _CounterDemoState extends State<CounterDemo> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
title: const Text('Counter'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
const Text(
|
|
'You have pushed the button this many times:',
|
|
),
|
|
ValueListenableBuilder(
|
|
valueListenable: widget.counter,
|
|
builder: (context, value, child) => Text(
|
|
'$value',
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () { widget.counter.value++; },
|
|
tooltip: 'Increment',
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|