Flutter, Number Counter app

Vignesh Prakash
2 min readMar 29, 2018

--

We created simple flutter app. This app only for increasing and decreasing the number.

Main and MaterialApp

MaterialApp class creates an instance of WidgetsApp.

void main() {
runApp(
new Center(
child: new MyApp(),
),
);
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Number Count",
theme: new ThemeData(
primarySwatch: Colors.blueGrey
),
home: new NumberCountDemo(),
);
}
}
class NumberCountDemo extends StatefulWidget {
@override
_NumberCountDemoState createState() => new _NumberCountDemoState();
}

Variable initialization

int _n = 0;

Declare and initialize a variable. Using underscore, variable will be a Private member.

Add function

void add() {
setState(() {
_n++;
});
}

Add function is used to increase the number size.

Minus function

void minus() {
setState(() {
if (_n != 0)
_n--;
});
}

Similarly, Minus function is used to decrease the number size. If condition is true, the value of n will be decreased.

Scaffold

Creates a visual scaffold for material design widgets.

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Number Count")
),
body: new Container(
child: new Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new FloatingActionButton(
onPressed: add,
child: new Icon(Icons.add, color: Colors.black,),
backgroundColor: Colors.white,),

new Text('$_n',
style: new TextStyle(fontSize: 60.0)),

new FloatingActionButton(
onPressed: minus,
child: new Icon(
const IconData(0xe15b, fontFamily: 'MaterialIcons'),
color: Colors.black),
backgroundColor: Colors.white,),
],
),
),
),
);
}

App Screenshots

--

--

Vignesh Prakash
Vignesh Prakash

Written by Vignesh Prakash

Flutter Monk | Software Engineer Specialist | Module Lead https://www.youtube.com/@Flutter-monk

Responses (9)