Flutter source code snippets

I’m creating this page as a collection of Flutter source code snippets. These are early days, but here you go.

Note also that my Flutter Quick Reference has many more examples as well.

Replacement home page

Here’s a link to my Flutter replacement home page code.

AlertDialog

void _showAlertDialog() {
  const msg = '''
    The slideshow requires at least two images to run.
    Please add more images using the Manage Images screen.''';
  final msg2 = convertMultilineStringToOneParagraph(msg);

  final dialog = AlertDialog(
      title: const Text('Add More Images'),
      content: SingleChildScrollView(
        child: ListBody(
          children: <Widget>[
            Text(msg2),
          ],
        ),
      )
  );
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return dialog;
    },
  );
}

Navigator/Navigation

Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => const SomeOtherWidget())

SnackBar

ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Your text here')));

CircularProgressIndicator

Widget circularProgressIndicator() {
   return const Center(child: SizedBox(width: 60, height: 60, child: CircularProgressIndicator()));
}

setState

setState(() {
  // your model-update code here
});