Created with <3 with dartpad.dev.
Last active
September 4, 2023 13:26
-
-
Save yungwarlock/48536f2ed3ce22d4c3d663a2996e486c to your computer and use it in GitHub Desktop.
SchedulerBinding
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 "package:flutter/scheduler.dart"; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: const Icon(Icons.star), | |
onPressed: () { | |
// This schedules an action to run at a later time | |
SchedulerBinding.instance.addPostFrameCallback((timeStamp) { | |
print("Hello"); | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
content: Text("Clicked"), | |
), | |
); | |
}); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Text( | |
'Hello, World!', | |
style: Theme.of(context).textTheme.headlineMedium, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment