init static method
Future<void>
init(
- BuildContext context, {
- Size designSize = defaultSize,
- bool splitScreenMode = false,
- bool minTextAdapt = false,
Initializing the library.
Implementation
static Future<void> init(
BuildContext context, {
Size designSize = defaultSize,
bool splitScreenMode = false,
bool minTextAdapt = false,
}) async {
final navigatorContext = Navigator.maybeOf(context)?.context as Element?;
final mediaQueryContext =
navigatorContext?.getElementForInheritedWidgetOfExactType<MediaQuery>();
final initCompleter = Completer<void>();
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((_) {
mediaQueryContext?.visitChildElements((el) => _instance._context = el);
if (_instance._context != null) initCompleter.complete();
});
final deviceData = MediaQuery.maybeOf(context).nonEmptySizeOrNull();
final deviceSize = deviceData?.size ?? designSize;
final orientation = deviceData?.orientation ??
(deviceSize.width > deviceSize.height
? Orientation.landscape
: Orientation.portrait);
_instance
.._context = context
.._uiSize = designSize
.._splitScreenMode = splitScreenMode
.._minTextAdapt = minTextAdapt
.._orientation = orientation
.._screenWidth = deviceSize.width
.._screenHeight = deviceSize.height;
_instance._elementsToRebuild?.forEach((el) => el.markNeedsBuild());
return initCompleter.future;
}