一.组件
1.Container(容器)
Container({
Key key,
this.alignment,
this.padding,
Color color,
Decoration decoration,
this.foregroundDecoration,
double width,
double height,
BoxConstraints constraints,
this.margin,
this.transform,
this.child,
})
1。圆角边框
Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(6)),
color: const Color(0xfff4f4f4),
border: Border.all(color: const Color(0x00000000), width: 0.5),
),
),
ps:decoration内的color属性与自身Container的color冲突,即只能存在一个
2.TextField(输入框)
const TextField({
Key key,
this.controller,
this.focusNode,
this.decoration = const InputDecoration(),
TextInputType keyboardType,
this.textInputAction,
this.textCapitalization = TextCapitalization.none,
this.style,
this.textAlign = TextAlign.start,
this.textDirection,
this.autofocus = false,
this.obscureText = false,
this.autocorrect = true,
this.maxLines = 1,
this.maxLength,
this.maxLengthEnforced = true,
this.onChanged,
this.onEditingComplete,
this.onSubmitted,
this.inputFormatters,
this.enabled,
this.cursorWidth = 2.0,
this.cursorRadius,
this.cursorColor,
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
this.enableInteractiveSelection,
this.onTap,
})
InputDecoration({
this.icon,
this.labelText,
this.labelStyle,
this.helperText,
this.helperStyle,
this.hintText,
this.hintStyle,
this.hintMaxLines,
this.errorText,
this.errorStyle,
this.errorMaxLines,
this.hasFloatingPlaceholder = true,
this.isDense,
this.contentPadding,
this.prefixIcon,
this.prefix,
this.prefixText,
this.prefixStyle,
this.suffixIcon,
this.suffix,
this.suffixText,
this.suffixStyle,
this.counter,
this.counterText,
this.counterStyle,
this.filled,
this.fillColor,
this.errorBorder,
this.focusedBorder,
this.focusedErrorBorder,
this.disabledBorder,
this.enabledBorder,
this.border,
this.enabled = true,
this.semanticCounterText,
this.alignLabelWithHint,
})
1。圆角边框
TextField(
decoration: InputDecoration(
hintText: "输入关键字搜寻商品",
prefixIcon: const Icon(Icons.search),
suffixIcon: const Icon(Icons.search),
border: _buildOutlineInputBorder(),
focusedBorder: _buildOutlineInputBorder(),
disabledBorder: _buildOutlineInputBorder(),
enabledBorder: _buildOutlineInputBorder(),
focusedErrorBorder: _buildOutlineInputBorder(),
errorBorder: _buildOutlineInputBorder(),
contentPadding: const EdgeInsets.all(0),
filled: true,
fillColor: Colors.black12,
),
cursorColor: Colors.black,
onSubmitted: (value) {
},
)
OutlineInputBorder _buildOutlineInputBorder() {
return const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide.none);
}
ps:默认的OutlineInputBorder会带有一点点边框弧度,可以设置 Radius.circular(0) 作为直角边框
3.Wrap(流式布局)
Wrap({
Key key,
this.direction = Axis.horizontal,
this.alignment = WrapAlignment.start,
this.spacing = 0.0,
this.runAlignment = WrapAlignment.start,
this.runSpacing = 0.0,
this.crossAxisAlignment = WrapCrossAlignment.start,
this.textDirection,
this.verticalDirection = VerticalDirection.down,
List<Widget> children = const <Widget>[],
})
4.Column(纵向线性布局)
Column({
Key key,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
MainAxisSize mainAxisSize = MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection textDirection,
VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline textBaseline,
List<Widget> children = const <Widget>[],
})
二.常用方法
1.获取屏幕宽度
final size = MediaQuery.of(context).size;
final width = size.width;
final height = size.height;
import 'dart:ui';
final width = window.physicalSize.width;
final height = window.physicalSize.height;
|