From 373d13767fe9384b06af018e8c54d6e2a834ff77 Mon Sep 17 00:00:00 2001 From: AhsanRns Date: Tue, 7 May 2024 10:47:39 +0500 Subject: [PATCH] feat: screen responsiveness --- evently/lib/main.dart | 12 ++++++++++++ evently/lib/utils/constants.dart | 1 + evently/lib/utils/screen_responsive.dart | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 evently/lib/utils/constants.dart create mode 100644 evently/lib/utils/screen_responsive.dart diff --git a/evently/lib/main.dart b/evently/lib/main.dart index 0cbbca978f..250bed3617 100644 --- a/evently/lib/main.dart +++ b/evently/lib/main.dart @@ -1,12 +1,19 @@ +import 'dart:ui'; + import 'package:easy_localization/easy_localization.dart'; +import 'package:evently/utils/constants.dart'; import 'package:evently/utils/evently_app_theme.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +bool isTablet = false; + void main() async { WidgetsFlutterBinding.ensureInitialized(); await EasyLocalization.ensureInitialized(); + isTablet = _getIsCurrentDeviceTablet(); + runApp( EasyLocalization( supportedLocales: const [ @@ -55,3 +62,8 @@ class MyApp extends StatelessWidget { ); } } + +bool _getIsCurrentDeviceTablet() { + final MediaQueryData mediaQuery = MediaQueryData.fromView(PlatformDispatcher.instance.implicitView!); + return mediaQuery.size.shortestSide >= tabletMinWidth; +} diff --git a/evently/lib/utils/constants.dart b/evently/lib/utils/constants.dart new file mode 100644 index 0000000000..40621e4583 --- /dev/null +++ b/evently/lib/utils/constants.dart @@ -0,0 +1 @@ +const double tabletMinWidth = 600; diff --git a/evently/lib/utils/screen_responsive.dart b/evently/lib/utils/screen_responsive.dart new file mode 100644 index 0000000000..6a7510bf5c --- /dev/null +++ b/evently/lib/utils/screen_responsive.dart @@ -0,0 +1,18 @@ +import 'package:evently/main.dart'; +import 'package:flutter/material.dart'; + +class ScreenResponsive extends StatelessWidget { + final WidgetBuilder mobileScreen; + final WidgetBuilder tabletScreen; + + const ScreenResponsive({super.key, required this.mobileScreen, required this.tabletScreen}); + + @override + Widget build(BuildContext context) { + if (isTablet) { + return tabletScreen(context); + } + + return mobileScreen(context); + } +}