98 lines
2.5 KiB
Dart
98 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fluttery/fluttery.dart';
|
|
import 'package:fluttery/logger.dart';
|
|
import 'package:fluttery/worker.dart';
|
|
|
|
Future<void> 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>();
|
|
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<Logger>().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<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
int _counter = 0;
|
|
|
|
void _incrementCounter() {
|
|
App.service<Worker>().spawn("worker-$_counter", () async {
|
|
App.service<Logger>().info("test");
|
|
|
|
await Future.delayed(const Duration(seconds: 10));
|
|
|
|
App.service<Logger>().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: <Widget>[
|
|
const Text('You have pushed the button this many times:'),
|
|
Text(
|
|
'$_counter',
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
print(
|
|
"active workers: ${App.service<Worker>().getActiveWorkers().length}",
|
|
);
|
|
},
|
|
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.
|
|
);
|
|
}
|
|
}
|