Skip to content

Instantly share code, notes, and snippets.

@sergeykondr
Last active May 3, 2020 23:41
Show Gist options
  • Save sergeykondr/96cf21c18b70441d1c1c99d8d47a836a to your computer and use it in GitHub Desktop.
Save sergeykondr/96cf21c18b70441d1c1c99d8d47a836a to your computer and use it in GitHub Desktop.
counter_app
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Counter',
theme: ThemeData(primaryColor: Colors.indigoAccent[200]),
home: Scaffold(
backgroundColor: Colors.indigoAccent[100],
appBar: AppBar(
title: Text('Counter'),
centerTitle: true,
),
body: Center(
child: Container(
padding: EdgeInsets.all(110),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Tap "-" to decrement',
style: TextStyle(color: Colors.white),
),
CounterWidget(),
Text(
'Tap "+" to encrement',
style: TextStyle(color: Colors.white),
),
],
),
),
),
),
);
}
}
class CounterWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CounterWidgetState();
}
}
class _CounterWidgetState extends State<CounterWidget> {
int _count = 50;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
//crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: IconButton(
icon: Icon(Icons.remove),
onPressed: () {
setState(() {
_count--;
});
},
),
),
Container(
child: Text(
'$_count',
style: TextStyle(fontSize: 22),
),
),
Container(
child: IconButton(
icon: Icon(Icons.add),
onPressed: () {
setState(() {
_count++;
});
},
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment