Skip to content

Instantly share code, notes, and snippets.

@suragch
Created April 9, 2021 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suragch/3d06b11a531e296f7fb783a1d6e3e287 to your computer and use it in GitHub Desktop.
Save suragch/3d06b11a531e296f7fb783a1d6e3e287 to your computer and use it in GitHub Desktop.
Minimalist state management: Timer tutorial: timer page UI
import 'package:flutter/material.dart';
class TimerPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('building MyHomePage');
return Scaffold(
appBar: AppBar(title: Text('My Timer App')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TimerTextWidget(),
SizedBox(height: 20),
ButtonsContainer(),
],
),
),
);
}
}
class TimerTextWidget extends StatelessWidget {
const TimerTextWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Text(
'00:10',
style: Theme.of(context).textTheme.headline2,
);
}
}
class ButtonsContainer extends StatelessWidget {
const ButtonsContainer({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PauseButton(),
SizedBox(width: 20),
ResetButton(),
],
);
}
}
class StartButton extends StatelessWidget {
const StartButton({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () {},
child: Icon(Icons.play_arrow),
);
}
}
class PauseButton extends StatelessWidget {
const PauseButton({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () {},
child: Icon(Icons.pause),
);
}
}
class ResetButton extends StatelessWidget {
const ResetButton({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () {},
child: Icon(Icons.replay),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment