1 | initial version |
In order to initiate a process on the main isolate instead of a background task in Dart, we can make use of the runApp()
method which is part of the Flutter framework. This method takes a widget and runs it on the main isolate:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text('Hello World!'),
);
}
}
In this example, the runApp()
method is called with an instance of the MyApp
widget, which is then executed on the main isolate. This results in the text 'Hello World!' being displayed on the screen.