- 1、 Initialize by
ScreenAdapter
.
void main() {
// over here !!!
ScreenAdapter.ensureInitialized(designWidth: 400);
runApp(const MyApp());
}
- 2、Transform
MediaQueryData
byScreenAdapter
.
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
// over here !!!
builder: ScreenAdapter.compatBuilder,
);
}
or
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
// over here !!!
builder: (context, child) => MediaQuery(
data: ScreenAdapter.compatMediaQueryData(context),
child: child ?? const SizedBox.shrink(),
),
);
}