Main coves client
1import 'package:flutter/material.dart';
2
3/// Utility class for responsive layout detection and sizing.
4///
5/// Provides tablet detection and content width constraints for
6/// adapting layouts between phone and tablet form factors.
7class ResponsiveUtils {
8 /// Tablets have shortestSide >= 600dp (Material Design guidelines)
9 static const double tabletBreakpoint = 600;
10
11 /// Maximum content width for readability on large screens.
12 ///
13 /// 640px provides an optimal line length of ~70-80 characters for body text,
14 /// which research shows maximizes reading comprehension and comfort.
15 /// This value also aligns with common content-width patterns in web design.
16 static const double maxContentWidth = 640;
17
18 /// Returns true if device is a tablet (based on shortest side).
19 ///
20 /// Uses shortestSide to handle both portrait and landscape orientations
21 /// consistently - a tablet is still a tablet regardless of rotation.
22 static bool isTablet(BuildContext context) {
23 return MediaQuery.sizeOf(context).shortestSide >= tabletBreakpoint;
24 }
25
26 /// Wraps [child] with centered max-width constraints on tablets.
27 ///
28 /// On phones, returns the child unchanged.
29 /// On tablets, centers the child within [maxContentWidth] constraints.
30 static Widget wrapForTablet(BuildContext context, Widget child) {
31 if (!isTablet(context)) {
32 return child;
33 }
34 return Center(
35 child: ConstrainedBox(
36 constraints: const BoxConstraints(maxWidth: maxContentWidth),
37 child: child,
38 ),
39 );
40 }
41}