Created
June 17, 2020 10:29
-
-
Save passsy/f4fd3fd0c72cee180a84b03ba789409a to your computer and use it in GitHub Desktop.
wrap_content match_parent in Flutter
This file contains 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 'package:flutter/material.dart'; | |
Future<void> main() async { | |
runApp(Builder( | |
builder: (context) => const MyApp(), | |
)); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({ | |
Key key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text("Title"), | |
), | |
body: Align( | |
alignment: Alignment.topCenter, | |
child: AndroidLayout( | |
height: 48, | |
width: wrap_content, // <-- Replace wrap_content with match_parent to fix the layout | |
// width: match_parent, | |
child: Container( | |
color: Colors.black26, | |
child: Stack( | |
alignment: Alignment.center, | |
children: const [ | |
Positioned( | |
left: 8, | |
top: 0, | |
bottom: 0, | |
child: Icon(Icons.arrow_back), | |
), | |
Text("Centered"), | |
], | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class AndroidLayout extends StatelessWidget { | |
const AndroidLayout({Key key, @required this.width, @required this.height, this.child}) : super(key: key); | |
final double width; | |
final double height; | |
final Widget child; | |
@override | |
Widget build(BuildContext context) { | |
return ConstrainedBox( | |
constraints: BoxConstraints( | |
minWidth: width, | |
minHeight: height, | |
), | |
child: child, | |
); | |
} | |
} | |
const double match_parent = double.infinity; | |
const double wrap_content = 0.0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment