我正在创建一个包含 10 个以上文本框的表单,因此我创建了一个小部件“textformfield”并将其命名为可重用小部件。我也想在每个文本框上都有一个图标,它会根据文本框内容而有所不同。
这是我做的
import 'package:flutter/material.dart';
//import 'package:attendance_system_app/new.dart';
class Textformfield extends StatelessWidget {
final String hinttext;
final double font;
final Color fontcolor;
final Icon icon;
final FontWeight fontweight;
final TextEditingController controller;
const Textformfield({
Key key,
this.hinttext,
this.font,
this.icon,
this.fontcolor,
this.fontweight,
this.controller
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText:hinttext,
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),
prefixIcon: Icon(
icon == null ? Container() :
icon,
//color: Colors.blue,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 16,
color: Colors.grey,
),
enabledBorder: new OutlineInputBorder(
borderRadius: const BorderRadius.all(Radius.circular(12)),
borderSide: new BorderSide(
color: Colors.black, width: 2,),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 2),
),
));
}
}