Widget cycles

Stateless Stateful
State doesn’t change over time: every data inside must be constant State CAN change over time
Build function only runs once when it’s created setState() triggers the build function
// choose_location.dart
import 'package:flutter/material.dart';

class ChooseLocation extends StatefulWidget {
  @override
  _ChooseLocationState createState() => _ChooseLocationState();
}

class _ChooseLocationState extends State<ChooseLocation> {

  int counter = 0;

  @override
  void initState() { // fires once when we load it
    super.initState();
    print('initState function ran');
  }



  @override
  Widget build(BuildContext context) { // fires every time we build
    print('build function ran');
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        backgroundColor: Colors.blue[900],
        title: Text('Choose location'),
        centerTitle: true,
        elevation: 0,
      ),
      body: RaisedButton(
        onPressed: (){
          setState(() { // trigger build widget to update data on screen
            counter += 1;
          });
        },
        child: Text('counter is $counter'),
      )
    );
  }
}