I'm making a responsive widget in Flutter (this question was asked on Stack Overflow). My app shows the mobile screen when using a mobile device, the tablet screen when using a tablet device, and the desktop screen when using a desktop device. However, my mobile device shows the tablet screen when I rotate it, even though I'm using a mobile.
I tried this package but still get the same result.
My code:
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
class Responsive extends StatelessWidget {
const Responsive({required this.mobile, required this.tablet, required this.desktop, super.key});
final Widget mobile;
final Widget tablet;
final Widget desktop;
static bool isMobile(BuildContext context) => SizerUtil.deviceType == DeviceType.mobile && SizerUtil.deviceType != DeviceType.tablet;
static bool isTablet(BuildContext context) => SizerUtil.deviceType != DeviceType.mobile && SizerUtil.deviceType == DeviceType.tablet;
static bool isDesktop(BuildContext context) => SizerUtil.deviceType != DeviceType.mobile && SizerUtil.deviceType != DeviceType.tablet;
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
debugPrint("isMobile: ${isMobile(context)}");
debugPrint("isTablet: ${isTablet(context)}");
debugPrint("isDesktop: ${isDesktop(context)}");
return isDesktop(context)
? desktop
: isTablet(context)
? tablet
: mobile;
},
);
}
import 'package:flutter/material.dart';
import 'package:project/desktop_screen.dart';
import 'package:project/mobile_screen.dart';
import 'package:project/tablet_screen.dart';
class MainScreen extends ConsumerWidget {
const MainScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return Responsive(
mobile: const MobileScreen(),
tablet: const TabletScreen(),
desktop: const DesktopScreen(),
);
}
}
Feel free to leave a comment if you need more information.
Why does my mobile device show a tablet screen when rotated, even though I'm using a mobile device? I would appreciate any help. Thank you in advance!