Skip to content

Instantly share code, notes, and snippets.

@passsy

passsy/main.dart

Created Jun 17, 2020
Embed
What would you like to do?
wrap_content match_parent in Flutter
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