Skip to content

Instantly share code, notes, and snippets.

@felangel
Created June 18, 2020 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/b5b9e50b233592a79940c2b8a2752b71 to your computer and use it in GitHub Desktop.
Save felangel/b5b9e50b233592a79940c2b8a2752b71 to your computer and use it in GitHub Desktop.
StatefulWidget demo
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: MyChild(),
floatingActionButton: FloatingActionButton(
onPressed: () => setState(() {}),
child: Icon(Icons.refresh),
),
);
}
}
class MyChild extends StatefulWidget {
@override
State<MyChild> createState() => _MyChildState();
}
class _MyChildState extends State<MyChild> {
var i = 0;
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text('$i'),
onPressed: () => setState(() => i++),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment