Skip to content

Instantly share code, notes, and snippets.

@stephaniefash
Created July 7, 2020 15:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stephaniefash/37a682f91782557bd09897256f33ee54 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class CounterWidget extends StatelessWidget {
int _counter = 0; //The class is immutable so this instance field should be final.
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_counter.toString()),
RaisedButton(
onPressed: () {
_counter++; // Will not increment because there is no internal state.
},
child: Text('Press me'),
)
]),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment