Flutter Widget Container
Flutter Widget Container là một trong những widget cơ bản của Flutter. Widget Container sử dụng để bao (bọc) một widget khác như Text và giúp widget con này có các thuộc tính như margin, padding…
Ví dụ Flutter Widget Container
import 'package:flutter/material.dart'; void main() { runApp(ConatinerDemo()); } class ConatinerDemo extends StatelessWidget { @override Widget build(BuildContext context) { return Container( // child: Text('Heloo World', textDirection: TextDirection.ltr), margin: const EdgeInsets.all(10.0), color: Colors.amber[600], width: 48.0, height: 48.0, ); } }
Các thuộc tính của Flutter Widget Container
Container Container({Key key, AlignmentGeometry alignment, EdgeInsetsGeometry padding, Color color, Decoration decoration, Decoration foregroundDecoration, double width, double height, BoxConstraints constraints, EdgeInsetsGeometry margin, Matrix4 transform, AlignmentGeometry transformAlignment, Widget child, Clip clipBehavior = Clip.none})
Dưới đây là các thuộc tính và phương thức thường gặp của
alignment
→ AlignmentGeometry? Căn lề widget con so với Container (Align the child within the container).finalchild
→ Widget? Widget con được bao (bọc) bởi container (The child contained by the container).finalcolor
→ Color? Màu sắc nền (phía sau) widget child của container (The color to paint behind the child).
finalconstraints
→ BoxConstraints?Additional constraints to apply to the child. […]finaldecoration
→ Decoration?The decoration to paint behind the child. […]finalforegroundDecoration
→ Decoration?The decoration to paint in front of the child.finalmargin
→ EdgeInsetsGeometry?Empty space to surround the decoration and child.finalpadding
→ EdgeInsetsGeometry?Empty space to inscribe inside the decoration. The child, if any, is placed inside this padding. […]finaltransform
→ Matrix4?The transformation matrix to apply before painting the container.finaltransformAlignment
→ AlignmentGeometry?The alignment of the origin, relative to the size of the container, if transform is specified. […]final
Các phương thức của widget Container
build(BuildContext
context)
→ Widget. Describes the part of the user interface represented by this widget.
override
createElement()
→ StatelessElement. Creates a StatelessElement to manage this widget’s location in the tree.
inheritedtoString({DiagnosticLevel minLevel: DiagnosticLevel.info})
→ String. A string representation of this object. inheritedtoStringDeep({String prefixLineOne: '', String? prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug})
→ String. Returns a string representation of this node and its descendants.
inheritedtoStringShort()
→ String. A short, textual description of this widget.
inherited