Skip to content

Instantly share code, notes, and snippets.

@suragch
Created December 20, 2021 05:07
Show Gist options
  • Save suragch/c7c8d111cb1d76e5506bbd4c32015883 to your computer and use it in GitHub Desktop.
Save suragch/c7c8d111cb1d76e5506bbd4c32015883 to your computer and use it in GitHub Desktop.
Stopping a DartPad app
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