Skip to content

Latest commit

 

History

History
48 lines (42 loc) · 1.03 KB

README.md

File metadata and controls

48 lines (42 loc) · 1.03 KB

Usage

  • 1、 Initialize by ScreenAdapter.
void main() {
  // over here !!!
  ScreenAdapter.ensureInitialized(designWidth: 400);
  runApp(const MyApp());
}
  • 2、Transform MediaQueryData by ScreenAdapter.
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(),
    ),
  );
}