counter_app.dart (build)
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: _bgColor,
appBar: AppBar(
title: const Text('Counter Advanced'),
backgroundColor: Colors.transparent,
),
body: Column(
children: [
Expanded(
flex: 2,
child: Center(
child: AnimatedSwitcher(
duration: Duration(milliseconds: 300),
child: Text(
'$_counter',
key: ValueKey<int>(_counter),
style: TextStyle(
fontSize: 120,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: LinearProgressIndicator(
value: _counter / _maxValue,
backgroundColor: Colors.white30,
valueColor: AlwaysStoppedAnimation(Colors.white),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
onPressed: _decrement,
child: Icon(Icons.remove),
),
FloatingActionButton(
onPressed: _reset,
child: Icon(Icons.refresh),
),
FloatingActionButton(
onPressed: _increment,
child: Icon(Icons.add),
),
],
),
Expanded(
flex: 1,
child: ListView.builder(
itemCount: _history.length,
itemBuilder: (ctx, i) => ListTile(
title: Text(_history[i]),
),
),
),
],
),
);
}
}
AnimatedSwitcherAnimasi transisi saat angka berganti
LinearProgressIndicatorBar progres counter / maxValue
key: ValueKeyMemberitahu Flutter widget berubah