Last active
May 10, 2020 00:07
-
-
Save geektutor/a9313872809c03d9e6c52c55883ec916 to your computer and use it in GitHub Desktop.
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Day 9 Task', | |
theme: ThemeData.dark(), | |
home: MyHomePage(title: 'Day 9 task'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int counter = 0; | |
String error = 'You have pushed the button this many times:'; | |
void increment() { | |
setState(() { | |
counter++; | |
error = 'You have pushed the button this many times:'; | |
}); | |
} | |
void decrement() { | |
setState(() { | |
if (counter > 0) { | |
counter--; | |
} else { | |
error = 'You cant go below 0'; | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'$error', | |
), | |
Text( | |
'$counter', | |
style: Theme.of(context).textTheme.headline4, | |
) | |
], | |
), | |
), | |
bottomNavigationBar: BottomAppBar( | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: <Widget>[ | |
FloatingActionButton( | |
child: Icon(Icons.remove), | |
onPressed: () { | |
decrement(); | |
}, | |
backgroundColor: Color(0xFF009688), | |
), | |
FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () { | |
increment(); | |
}, | |
backgroundColor: Color(0xFF009688), | |
), | |
], | |
), | |
), | |
// This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment