Created
February 2, 2020 10:16
-
-
Save preetjdp/6d43e30eb6febfcf7ad0eec8555035db 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'; | |
| final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| final DataItem dataItem = DataItem(); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| floatingActionButton: FloatingActionButton.extended( | |
| label: Text('Append'), | |
| icon: Icon(Icons.add), | |
| onPressed: () { | |
| dataItem.appendValue(); | |
| }, | |
| ), | |
| body: Center( | |
| child: dataItem, | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class DataItem extends StatefulWidget { | |
| final _DataItemState dataItemState = new _DataItemState(); | |
| void appendValue() => dataItemState.appendValue(); | |
| @override | |
| _DataItemState createState() => dataItemState; | |
| } | |
| class _DataItemState extends State<DataItem> { | |
| int value = 0; | |
| void appendValue() { | |
| setState(() { | |
| value ++; | |
| }); | |
| } | |
| @override | |
| build(BuildContext context) { | |
| return new Container( | |
| child: Text( | |
| value.toString() | |
| )); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment