Created
July 27, 2020 20:19
-
-
Save dolpheen/7e096b6bc8f535660d641554a444263e to your computer and use it in GitHub Desktop.
Replaces system viewconfiguration
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/rendering.dart'; | |
class CustomWidgetsFlutterBinding extends WidgetsFlutterBinding { | |
@override | |
ViewConfiguration createViewConfiguration() { | |
final ratio = 4.0; | |
return ViewConfiguration( | |
size: window.physicalSize / ratio, | |
devicePixelRatio: ratio, | |
); | |
} | |
static WidgetsBinding ensureInitialized() { | |
if (WidgetsBinding.instance == null) { | |
CustomWidgetsFlutterBinding(); | |
} | |
return WidgetsBinding.instance; | |
} | |
} | |
void main() { | |
CustomWidgetsFlutterBinding.ensureInitialized() | |
..attachRootWidget( | |
Center( | |
child: Container(width: 50, height: 50, color: Colors.red), | |
), | |
) | |
..scheduleWarmUpFrame(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment