Created
December 20, 2021 05:07
-
-
Save suragch/c7c8d111cb1d76e5506bbd4c32015883 to your computer and use it in GitHub Desktop.
Stopping a DartPad app
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'; | |
import 'dart:async'; | |
void main() { | |
runApp(MyApp()); | |
runDart(); | |
} | |
Timer? myTimer; | |
void runDart() { | |
int iter = 0; | |
myTimer = Timer.periodic(const Duration(milliseconds: 10), (timer) { | |
iter++; | |
int temp = iter %1000; | |
print("iter = $iter"); | |
print("iter %1000 = $temp"); | |
}); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Center( | |
child: ElevatedButton( | |
child: const Text('Stop'), | |
onPressed: () { | |
myTimer?.cancel(); | |
}, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment