Skip to content

Instantly share code, notes, and snippets.

@preetjdp
Created February 2, 2020 10:16
Show Gist options
  • Select an option

  • Save preetjdp/6d43e30eb6febfcf7ad0eec8555035db to your computer and use it in GitHub Desktop.

Select an option

Save preetjdp/6d43e30eb6febfcf7ad0eec8555035db to your computer and use it in GitHub Desktop.
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