- 添加 .gitignore 文件,配置项目忽略项 - 创建 .metadata 文件,记录项目元数据 - 编写 README.md,介绍项目基本信息 - 配置 analysis_options.yaml,设置代码分析规则 - 创建 Android 相关文件和目录结构 - 创建 iOS 相关文件和目录结构
64 lines
2.2 KiB
Dart
64 lines
2.2 KiB
Dart
import 'dart:io'; // 新增:导入 dart:io 库以使用 File 类
|
|
import 'package:flutter/material.dart';
|
|
import 'package:item_tracker/models/item_model.dart'; // 引用 item_model
|
|
|
|
class AddItemScreen extends StatelessWidget {
|
|
final TextEditingController _nameController = TextEditingController();
|
|
final TextEditingController _descriptionController = TextEditingController();
|
|
String? _imagePath;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('添加物品'),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
TextField(
|
|
controller: _nameController,
|
|
decoration: InputDecoration(labelText: '名称'),
|
|
),
|
|
SizedBox(height: 16),
|
|
TextField(
|
|
controller: _descriptionController,
|
|
decoration: InputDecoration(labelText: '简介'),
|
|
maxLines: 3,
|
|
),
|
|
SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
// 这里可以添加选择图片的逻辑
|
|
// 例如:使用 image_picker 插件
|
|
// ImagePicker().pickImage(source: ImageSource.gallery);
|
|
},
|
|
child: Text('选择图片'),
|
|
),
|
|
if (_imagePath != null)
|
|
Image.file(File(_imagePath!)), // 使用 File 类显示图片
|
|
SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
// 创建 Item 对象并处理提交逻辑
|
|
Item item = Item(
|
|
name: _nameController.text,
|
|
description: _descriptionController.text,
|
|
imagePath: _imagePath,
|
|
);
|
|
// 可以在这里处理图片路径
|
|
// 例如:上传图片到服务器
|
|
// 保存物品信息到数据库
|
|
print('名称: ${item.name}');
|
|
print('简介: ${item.description}');
|
|
print('图片路径: ${item.imagePath}');
|
|
},
|
|
child: Text('提交'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |