Created
October 4, 2023 11:15
-
-
Save LokieVikky/7c5d40d881a77bb627a0da6127d9ac3c to your computer and use it in GitHub Desktop.
Flutter Conf India Puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
theme: ThemeData.dark(), | |
home: const HomePage(), | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
const HomePage({super.key}); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
final _inputController = TextEditingController(); | |
String latitude = ""; | |
String longitude = ""; | |
String _getResult(String value) { | |
StringBuffer result = StringBuffer(); | |
int i = 0; | |
if (value.length % 2 != 0) { | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
content: Text( | |
'Invalid input key!', | |
), | |
), | |
); | |
} | |
while (i < value.length) { | |
String hb = value.substring(i, i + 2); | |
int dv = 0; | |
for (int j = 0; j < hb.length; j++) { | |
int hd = hb.codeUnitAt(j); | |
if (hd >= 48 && hd <= 57) { | |
dv += (hd - 48) * (j == 0 ? 16 : 1); | |
} else if (hd >= 65 && hd <= 70) { | |
dv += (hd - 65 + 10) * (j == 0 ? 16 : 1); | |
} else if (hd >= 97 && hd <= 102) { | |
dv += (hd - 97 + 10) * (j == 0 ? 16 : 1); | |
} else { | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
content: Text( | |
'Invalid input key!', | |
), | |
), | |
); | |
} | |
} | |
result.write(String.fromCharCode(dv)); | |
i += 2; | |
} | |
return result.toString(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Padding( | |
padding: const EdgeInsets.all(30.0), | |
child: Center( | |
child: SingleChildScrollView( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
//const Spacer(), | |
Image.network( | |
'https://raw.githubusercontent.com/flutterconfin/flutter-conf-data/main/fci_logo.png', | |
), | |
const SizedBox(height: 40), | |
//const FittedBox(child: SizedBox(height: 0, width: 0)), | |
TextField( | |
controller: _inputController, | |
style: const TextStyle( | |
fontSize: 18.0, | |
color: Colors.black, | |
), | |
decoration: InputDecoration( | |
hintText: 'Enter your key', | |
hintStyle: const TextStyle( | |
color: Colors.grey, | |
), | |
filled: true, | |
fillColor: Colors.white, | |
contentPadding: const EdgeInsets.all(16.0), | |
enabledBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(10.0), | |
borderSide: BorderSide( | |
color: Colors.grey.shade400, | |
), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderRadius: BorderRadius.circular(10.0), | |
borderSide: const BorderSide( | |
color: Colors.blue, | |
width: 2.0, | |
), | |
), | |
suffixIcon: IconButton( | |
onPressed: () { | |
if (_inputController.text.contains(',')) { | |
final input1 = _inputController.text.split(',')[0]; | |
final input2 = _inputController.text.split(',')[1]; | |
setState(() { | |
latitude = _getResult(input1); | |
longitude = _getResult(input2); | |
}); | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
content: Text( | |
'Note this coordinates and now search the location for this coordinates 🎉', | |
), | |
), | |
); | |
} else { | |
setState(() { | |
latitude = ''; | |
longitude = ''; | |
}); | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
content: Text( | |
'Invalid input key!', | |
), | |
), | |
); | |
} | |
}, | |
icon: const Icon( | |
Icons.arrow_forward_ios, | |
color: Colors.blue, | |
), | |
), | |
), | |
), | |
const SizedBox(height: 40), | |
if (latitude.isNotEmpty && longitude.isNotEmpty) | |
SizedBox( | |
width: MediaQuery.sizeOf(context).width, | |
child: Center( | |
child: SelectableText( | |
'Coordinates: $latitude,$longitude', | |
style: const TextStyle(fontSize: 20), | |
), | |
), | |
), | |
//const Spacer(), | |
], | |
), | |
), | |
), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment