Skip to content

Instantly share code, notes, and snippets.

@stegrams
Last active April 16, 2020 12:11
Show Gist options
  • Save stegrams/c2dcd3bf79326d7c9bf8356787bf755a to your computer and use it in GitHub Desktop.
Save stegrams/c2dcd3bf79326d7c9bf8356787bf755a to your computer and use it in GitHub Desktop.
Pawan Kumar‎'s code sample to turn country id to flag emoji
import 'package:flutter/material.dart';
const int flagOffset = 0x1F1E6;
const int asciiOffset = 0x41;
String codeToCountryEmoji(code) {
final char1 = code.codeUnitAt(0) - asciiOffset + flagOffset;
final char2 = code.codeUnitAt(1) - asciiOffset + flagOffset;
return String.fromCharCode(char1) + String.fromCharCode(char2);
}
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(
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Text(
codeToCountryEmoji("IN"),
style: TextStyle(fontSize: 100),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment