/
proxy_provider0.dart
69 lines (62 loc) · 1.8 KB
/
proxy_provider0.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/hex_counter.dart';
import '../models/value_notifier_counter.dart';
class ProxyProvider0Page extends StatelessWidget {
const ProxyProvider0Page();
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<VnCounter>(
create: (_) => VnCounter(),
builder: (context, child) => ProxyProvider0<HexCounter>(
create: (_) => HexCounter(),
update: (_, prev) => prev
..newValue = context.select((VnCounter vnCounter) => vnCounter.value),
child: child,
),
child: Scaffold(
appBar: AppBar(
title: const Text('ProxyProvider0()'),
),
body: const _CounterResults(),
floatingActionButton: const _FloatingButton(),
),
);
}
}
class _FloatingButton extends StatelessWidget {
const _FloatingButton();
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () => context.read<VnCounter>().increment(),
child: const Icon(Icons.add),
);
}
}
class _CounterResults extends StatelessWidget {
const _CounterResults();
@override
Widget build(BuildContext context) {
final dec = context.select((VnCounter counter) => counter.value);
final hex = context.select((HexCounter counter) => counter.hex);
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Decimal',
style: TextStyle(fontSize: 16.0),
),
Text(dec.toString()),
const SizedBox(height: 32.0),
const Text(
'Hexadecimal',
style: TextStyle(fontSize: 16.0),
),
Text(hex),
],
),
);
}
}