Created
February 17, 2022 20:41
-
-
Save yringler/cd5b018ba8a261933561d076c8fca203 to your computer and use it in GitHub Desktop.
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( | |
MaterialApp( | |
home: Scaffold( | |
body: Center(child: Calculator()), | |
), | |
), | |
); | |
} | |
class Calculator extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => _CalculatorState(); | |
} | |
class _CalculatorState extends State<Calculator> { | |
int code = 0; | |
@override | |
Widget build(BuildContext context) => Padding( | |
padding: const EdgeInsets.all(30.0), | |
child: ListView( | |
children: [ | |
const Text('Input numeric code below:'), | |
TextField( | |
autofocus: true, | |
decoration: const InputDecoration( | |
enabledBorder: UnderlineInputBorder( | |
borderSide: BorderSide(color: Colors.black))), | |
onChanged: (value) => setState(() { | |
code = int.tryParse(value) ?? 0; | |
})), | |
Text(convertToReasons(code).toList().join(' ')) | |
], | |
), | |
); | |
} | |
const None = 0; | |
const AutomationVisible = 0x1; | |
const UnexpectedEnvironmentVisible = 0x2; | |
const TooMuchTrafficVisible = 0x4; | |
const UnexpectedUsagePatternsVisible = 0x8; | |
const LowConfidenceScoreVisible = 0x10; | |
const OtherReasonVisible = 0x20; | |
const AutomationHidden = 0x40; | |
const UnexpectedEnvironmentHidden = 0x80; | |
const TooMuchTrafficHidden = 0x100; | |
const UnexpectedUsagePatternsHidden = 0x200; | |
const LowConfidenceScoreHidden = 0x400; | |
const OtherReasonHidden = 0x800; | |
Iterable<String> convertToReasons(int reason) sync* { | |
if (reason & AutomationVisible == AutomationVisible) { | |
yield 'AutomationVisible'; | |
} | |
if (reason & UnexpectedEnvironmentVisible == UnexpectedEnvironmentVisible) { | |
yield 'UnexpectedEnvironmentVisible'; | |
} | |
if (reason & TooMuchTrafficVisible == TooMuchTrafficVisible) { | |
yield 'TooMuchTrafficVisible'; | |
} | |
if (reason & UnexpectedUsagePatternsVisible == | |
UnexpectedUsagePatternsVisible) { | |
yield 'UnexpectedUsagePatternsVisible'; | |
} | |
if (reason & LowConfidenceScoreVisible == LowConfidenceScoreVisible) { | |
yield 'LowConfidenceScoreVisible'; | |
} | |
if (reason & OtherReasonVisible == OtherReasonVisible) { | |
yield 'OtherReasonVisible'; | |
} | |
if (reason & AutomationHidden == AutomationHidden) { | |
yield 'AutomationHidden'; | |
} | |
if (reason & UnexpectedEnvironmentHidden == UnexpectedEnvironmentHidden) { | |
yield 'UnexpectedEnvironmentHidden'; | |
} | |
if (reason & LowConfidenceScoreHidden == LowConfidenceScoreHidden) { | |
yield 'LowConfidenceScoreHidden'; | |
} | |
if (reason & OtherReasonHidden == OtherReasonHidden) { | |
yield 'OtherReasonHidden'; | |
} | |
if (reason & TooMuchTrafficHidden == TooMuchTrafficHidden) { | |
yield 'TooMuchTrafficHidden'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment