Skip to content

Instantly share code, notes, and snippets.

@maks
Created June 23, 2020 22:23
Show Gist options
  • Select an option

  • Save maks/c2b7255fcadc769e9f3cb318b5796a32 to your computer and use it in GitHub Desktop.

Select an option

Save maks/c2b7255fcadc769e9f3cb318b5796a32 to your computer and use it in GitHub Desktop.
Flutter Day
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(FlagCircle());
}
class FlagCircle extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _FlagCircleState();
}
}
class _FlagCircleState extends State<FlagCircle> {
static const _countries = [
'au',
'nz',
'us',
'fi',
'ua',
'se',
'de',
'dk',
'fr',
'ru',
'it',
'be',
'sg',
'no',
'nl',
'ch',
'at',
'gb',
'ee',
'mc',
];
List<String> countryCodes;
@override
void initState() {
super.initState();
init();
}
void init() {
_prepList(_countries);
Timer.periodic(Duration(milliseconds: 250), (timer) {
setState(() {
if (countryCodes.length == 1) {
timer.cancel();
}
_prepList(countryCodes);
});
});
}
void _prepList(List<String> prevList) {
countryCodes = prevList.sublist(1)..shuffle();
countryCodes[0] = 'au';
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text("Flutter Day!")),
body: Center(
child: Container(
width: 80,
child: ListView.builder(
shrinkWrap: true,
itemCount: countryCodes.length,
itemBuilder: (_, i) {
return _buildFlag(countryCodes[i]);
},
),
),
),
),
);
}
Widget _buildFlag(String countryCode) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: FlatButton(
onPressed: () => setState(() {
init();
}),
child: Image.network(
'https://www.countryflags.io/$countryCode/flat/64.png')),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment