claude nmsl
This commit is contained in:
1 parent
cd6491cdc5
commit
2ad6781049
10 files changed
+119
-35
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Breakpoints: phone < 600, tablet 600–900, desktop > 900
|
||||
const double _breakpointTablet = 600;
|
||||
const double _breakpointDesktop = 900;
|
||||
|
||||
/// Returns a responsive max width for content containers.
|
||||
/// - Phone: 500
|
||||
/// - Tablet: 700
|
||||
/// - Desktop: 900
|
||||
double responsiveMaxWidth(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
if (width >= _breakpointDesktop) return 900;
|
||||
if (width >= _breakpointTablet) return 700;
|
||||
return 500;
|
||||
}
|
||||
|
||||
/// Whether the screen is tablet-sized or wider.
|
||||
bool isTablet(BuildContext context) =>
|
||||
MediaQuery.of(context).size.width >= _breakpointTablet;
|
||||
|
||||
/// Whether the screen is desktop-sized or wider.
|
||||
bool isDesktop(BuildContext context) =>
|
||||
MediaQuery.of(context).size.width >= _breakpointDesktop;
|
||||
|
||||
/// Build columns for tablet/desktop — on phone, each item is full-width;
|
||||
/// on tablet+ they are laid out in [columns] columns.
|
||||
List<Widget> responsiveGrid({
|
||||
required BuildContext context,
|
||||
required List<Widget> children,
|
||||
int columns = 2,
|
||||
double spacing = 12,
|
||||
}) {
|
||||
final tablet = isTablet(context);
|
||||
if (!tablet) return children;
|
||||
|
||||
final rows = <Widget>[];
|
||||
final padded = <Widget>[];
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
padded.add(children[i]);
|
||||
if ((i + 1) % columns == 0 || i == children.length - 1) {
|
||||
final cols = <Widget>[];
|
||||
for (int j = 0; j < padded.length; j++) {
|
||||
cols.add(Expanded(child: padded[j]));
|
||||
}
|
||||
// pad incomplete last row with empty expanded widgets
|
||||
while (cols.length < columns) {
|
||||
cols.add(const Expanded(child: SizedBox.shrink()));
|
||||
}
|
||||
rows.add(Padding(
|
||||
padding: EdgeInsets.only(bottom: rows.isEmpty ? 0 : spacing),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (int j = 0; j < cols.length; j++) ...[
|
||||
if (j > 0) SizedBox(width: spacing),
|
||||
cols[j],
|
||||
],
|
||||
],
|
||||
),
|
||||
));
|
||||
padded.clear();
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
Reference in new issue
Block a user