LayoutBuilder Example
class Responsive extends StatelessWidget {
final Widget? mobile;
final Widget desktop;
const Responsive({Key? key, required this.desktop, this.mobile,})
: super(key: key);
static bool isMobile() =>
ScreenUtil().screenWidth < 700;
static bool isTablet() =>
ScreenUtil().screenWidth >= 700 &&
ScreenUtil().screenWidth < 1200 * c;
static bool isDesktop() => ScreenUtil().screenWidth >= 1200 * c;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth >= 700) {
return desktop;
} else {
return mobile ?? desktop;
}
},
);
}
}
LayoutBuilder 실 사용법!
- Constraints는 현재 Web의 size를 말한다.
'Flutter > Widget' 카테고리의 다른 글
[Widget] Material Widget (0) | 2021.12.09 |
---|---|
[Widget] MaterialStateProperty of Button (0) | 2021.12.09 |
[Widget] Is there a way to load async data on initState method? (0) | 2021.12.07 |
[Widget] CheckBox (0) | 2021.11.30 |
[Widget] TextField, TextFormField (validate) (0) | 2021.11.30 |