Skip to content

Instantly share code, notes, and snippets.

@sma
Last active January 16, 2022 19:05
Show Gist options
  • Save sma/b46251adf74bc4f1b5eba86f003d754d to your computer and use it in GitHub Desktop.
Save sma/b46251adf74bc4f1b5eba86f003d754d to your computer and use it in GitHub Desktop.
A Flag widget to display flags (doesn't work on Dart Pad)
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Displaying flags 🇺🇳 does not work on DartPad!')
),
body: Center(
child: MyWidget(),
),
),
);
}
}
const kFunWithFlags = 'ar be ca de ee fi gn hu ie jm kr ls md no om pe';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Wrap(
children: [
...kFunWithFlags.split(' ').map((code) => Flag(code: code, size: 96))
],
);
}
}
class Flag extends StatelessWidget {
const Flag({
Key? key,
required this.code,
this.size = 32,
}) : super(key: key);
final String code;
final double size;
@override
Widget build(BuildContext context) {
return SizedBox(
width: size,
height: size,
child: Text(
String.fromCharCodes([
127365 + code.codeUnitAt(0),
127365 + code.codeUnitAt(1),
]),
style: TextStyle(fontSize: size, height: 1.1),
textAlign: TextAlign.center,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment