suit
1. Initialize the adapter
import 'package:flutter/material.dart';
import 'package:suit/suit.dart';
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
Adapter.initialize(context);
return Scaffold();
}
}
- Cannot initialize under root widget
- An application only needs to be initialized once
- You can write it in any lifecycle hook, but for desktop application adaptation, it's better to write it in the
build
method
2. Import the package and write size by vh, vw
anywhere
- Method 1: 36.vw, 52.0.vw, 100vh
- Method 2: Adapter.setVW(25), Adapter.setVH(30)
- Method 3: Adapter.vw * 32, Adapter.vh * 75
Complete example:
import 'package:flutter/material.dart';
import 'package:suit/suit.dart';
void main() => runApp(MaterialApp(home: App()));
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
// You can write it to initialize adapter here
Adapter.initialize(context);
return Scaffold(
body: Container(
width: 25.vw,
height: 75.vh,
color: Colors.red
)
);
}
}