Created
August 10, 2020 19:23
-
-
Save Medvedoc/50a4ebd15f40fa31d68dd0843f961d79 to your computer and use it in GitHub Desktop.
My_tasks_Flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyCounterApp()); | |
class MyCounterApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
backgroundColor: Colors.blue[300], | |
appBar: AppBar( | |
title: Text('CounterApp', | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.bold, | |
)), | |
centerTitle: true, | |
), | |
body: Center( | |
child: Container( | |
child: Column( | |
textDirection: TextDirection.ltr, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Container( | |
child: Text( | |
'Tap "+" decrement', | |
style: TextStyle( | |
fontSize: 18.0, | |
color: Colors.white, | |
), | |
), | |
), | |
CounterWidget(), | |
Container( | |
child: Text( | |
'Tap "-" increment', | |
style: TextStyle( | |
fontSize: 18.0, | |
color: Colors.white, | |
), | |
), | |
), | |
], | |
), | |
), | |
), | |
)); | |
} | |
} | |
class CounterWidget extends StatefulWidget { | |
@override | |
_CounterWidgetState createState() => _CounterWidgetState(); | |
} | |
class _CounterWidgetState extends State<CounterWidget> { | |
int _count; | |
@override | |
void initState() { | |
_count = 50; | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(8.0), | |
color: Colors.blue[100], | |
), | |
margin: EdgeInsets.only(left:140, right:140, top:5, bottom:5), | |
child: Row( | |
textDirection: TextDirection.ltr, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
IconButton(icon: Icon(Icons.remove), onPressed: (){ | |
setState(() { | |
_count-=1; | |
}); | |
}), | |
Text('${(_count)}', | |
style: TextStyle( | |
fontSize: 30, | |
)), | |
IconButton(icon: Icon(Icons.add), onPressed: (){ | |
setState(() { | |
_count += 1; | |
}); | |
}), | |
]), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment