【发布时间】:2021-03-08 17:30:24
【问题描述】:
我正在尝试添加两个 TextField,其中将有两个部分。其中一个是学生编号,第二个是学校编号。
当我在用于学生编号的文本字段中写入 1234 并在学校编号的文本字段中写入 4321 时,我必须获取它们并将它们放在代码中的某个位置,如此处所示;
这是我在这里使用的代码块;
class DocUploadScreen extends StatefulWidget {
createState() => _DocUploadScreenState();
}
class _DocUploadScreenState extends State<DocUploadScreen> {
File _imageFile;
Future<void> _pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
setState(() {
_imageFile = selected;
});
}
void _clear() {
setState(() => _imageFile = null);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("FÖY YÜKLEME EKRANI"),
),
bottomNavigationBar: BottomAppBar(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(
Icons.photo_camera,
size: 30,
),
onPressed: () => _pickImage(ImageSource.camera),
color: Colors.blue,
),
IconButton(
icon: Icon(
Icons.photo_library,
size: 30,
),
onPressed: () => _pickImage(ImageSource.gallery),
color: Colors.red,
),
],
),
),
body: ListView(
children: <Widget>[
if (_imageFile != null) ...[
Container(
padding: EdgeInsets.all(32), child: Image.file(_imageFile)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
color: Colors.blueAccent,
textColor: Colors.white,
child: Icon(Icons.refresh),
onPressed: _clear,
),
],
),
Padding(
padding: const EdgeInsets.all(32),
child: Uploader(
file: _imageFile,
),
)
]
],
),
);
}
}
class Uploader extends StatefulWidget {
final File file;
Uploader({Key key, this.file}) : super(key: key);
createState() => _UploaderState();
}
class _UploaderState extends State<Uploader> {
final FirebaseStorage _storage =
FirebaseStorage(storageBucket: 'gs://emo-is0.appspot.com');
StorageUploadTask _uploadTask;
_startUpload() async {
我将从文本字段(schoolno 和 studentno)获取值:
String filePath = 'schoolno/studentno/documents/${DateTime.now()}.png';
StorageUploadTask _uploadTask =
_storage.ref().child(filePath).putFile(widget.file);
StorageTaskSnapshot taskSnapshot = await _uploadTask.onComplete;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
(InvoiceUploadScreen())));
}
我这里有 2 个问题;
- 我需要将 TextFields 放在哪里,以便我可以获取值并放在下面看到的位置,
- 如何从 TextFields 中获取值并将其放入?还有我如何在文本字段中使用验证器,因为学校和学生都不必提供才能用于上传到存储?
请指教!
【问题讨论】:
标签: firebase flutter dart firebase-storage textfield