import 'package:flutter/material.dart';
class ProductCreatePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ProductCreatePageState();
}
}
class _ProductCreatePageState extends State<ProductCreatePage> {
String titleValue;
String descriptionValue;
double priceValue;
//int是整數,double可以有小數
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(10.0),
//外層加一個container並加外距10
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Product Title'),
//input的標籤
onChanged: (String value) {
setState(() {
titleValue = value;
});
},
),
TextField(
maxLines: 4,
//可以有很多行
decoration: InputDecoration(labelText: 'Product Description'),
onChanged: (String value) {
setState(() {
descriptionValue = value;
});
},
),
TextField(
keyboardType: TextInputType.number,
//小鍵盤只有數字
decoration: InputDecoration(labelText: 'Product Price'),
onChanged: (String value) {
setState(() {
priceValue = double.parse(value);
//轉成小數
});
},
),
],
),
);
}
}
主題來源:
Learn Flutter & Dart to Build iOS & Android Apps