import 'package:flutter/material.dart'; import 'package:fluttery/fluttery.dart'; import 'package:fluttery/logger.dart'; import 'package:fluttery/worker.dart'; Future main() async { // Ensures that the Flutter engine and widget binding // are initialized before using async services or plugins WidgetsFlutterBinding.ensureInitialized(); // any services App.registerDefaultServices(); final logger = App.service(); logger.debug("[MAIN] Registered all default services"); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { App.service().info("test"); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { int _counter = 0; void _incrementCounter() { App.service().spawn("worker-$_counter", () async { App.service().info("test"); await Future.delayed(const Duration(seconds: 10)); App.service().info("end worker"); }); setState(() { _counter++; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Text('You have pushed the button this many times:'), Text( '$_counter', style: Theme.of(context).textTheme.headlineMedium, ), TextButton( onPressed: () { }, child: Text("Print workers"), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: const Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }