Last active
March 2, 2021 04:31
-
-
Save dened/e15c0e0bc625f59e8c747ea9c1d82a8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* https://dartpad.dev/e15c0e0bc625f59e8c747ea9c1d82a8b | |
*/ | |
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
final ValueNotifier<bool> useFix = ValueNotifier<bool>(false); | |
const int payloadLength = 70000; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
Widget build(BuildContext context) => MaterialApp( | |
home: Scaffold( | |
body: SafeArea( | |
child: Center( | |
child: SingleChildScrollView( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
Text('Use fix:', textScaleFactor: 1.5), | |
ValueListenableBuilder<bool>( | |
valueListenable: useFix, | |
builder: (context, currentValue, _) => Switch( | |
value: currentValue, | |
onChanged: (newValue) => useFix.value = newValue, | |
), | |
), | |
], | |
), | |
SizedBox(height: 50), | |
SizedBox( | |
child: CircularProgressIndicator(), | |
height: 75, | |
width: 75, | |
), | |
SizedBox(height: 50), | |
Text('Payload length: $payloadLength', | |
textScaleFactor: 1.25), | |
SizedBox(height: 15), | |
OutlinedButton( | |
child: Text('IMPACT ON EVENT LOOP'), | |
onPressed: () async => impactOnEventLoop(), | |
), | |
], | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
Future<void> impactOnEventLoop() async { | |
/// Если useFix.value == true, нужно добавить фикс, который позволит прогрессу крутитmся без зависания, а | |
/// коду искать простые числа. | |
final primeList = <int>[]; | |
final sourceData = generateSourceData(payloadLength); | |
for (final i in sourceData) { | |
if (!i.isPrime) continue; | |
primeList.add(i); | |
} | |
print('Number of primes: ${primeList.length}'); | |
} | |
Iterable<int> generateSourceData(int length) sync* { | |
for (var i = 0; i < length; i++) { | |
yield i; | |
} | |
} | |
extension IsPrimeX on int { | |
bool get isPrime { | |
if (this > 1) { | |
for (int i = 2; i < this; i++) if (this % i == 0) return false; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment