Last active
November 27, 2023 13:56
-
-
Save pszklarska/28b1dbc82f451cbd53f65afb5dbf2d1c to your computer and use it in GitHub Desktop.
Flutter Adaptable layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold(body: AdaptableRow()), | |
), | |
); | |
} | |
class AdaptableRow extends StatelessWidget { | |
final minWidth = 500.0; | |
@override | |
Widget build(BuildContext context) { | |
final screenWidth = MediaQuery.of(context).size.width; | |
return SingleChildScrollView( | |
scrollDirection: Axis.horizontal, | |
child: ConstrainedBox( | |
constraints: BoxConstraints( | |
maxWidth: max(screenWidth, minWidth), | |
), | |
child: Column( | |
children: [ | |
Container( | |
height: 200.0, | |
child: Row( | |
children: [ | |
Expanded( | |
flex: 2, | |
child: Container(color: Colors.yellow), | |
), | |
SizedBox(width: 10.0), | |
Expanded( | |
flex: 1, | |
child: Container(color: Colors.blue), | |
), | |
SizedBox(width: 10.0), | |
Expanded( | |
flex: 3, | |
child: Container(color: Colors.green), | |
), | |
SizedBox(width: 10.0), | |
Expanded( | |
flex: 1, | |
child: Container(color: Colors.pink), | |
), | |
], | |
), | |
), | |
SizedBox(height: 20.0), | |
Text('Screen width: $screenWidth'), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment