Heloo,我一直在尝试将我的 ValueNotifier
数据上传到 firebase,每当我这样做时,它都会为我拥有 .copyWith
这是我在做什么:
final recentNews = useProvider(allNewsProvider);
final allactivities = useProvider(allActivitiesProvider);
final _activity = useState(ActivitiesModel());
String imageUrl;
var pickedImage;
var uuid = Uuid();
final _formKey = useState(GlobalKey<FormState>());
final currentOrganization = useProvider(currentOrganizationProvider);
return Scaffold(
//the whole body with ui design
);
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: userRole == "Organization"
? currentOrganization.when(
data: (org) => FloatingActionButton(
child: Icon(Icons.add),
onPressed: () async {
await showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
child: SingleChildScrollView(
child: Form(
key: _formKey.value,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
crossAxisAlignment:
CrossAxisAlignment.center,
children: <Widget>[
CustomText(
text: "Add an Activity",
size: 22,
),
Icon(Icons.post_add)
],
),
Field(
label: "Title",
iconData: Icons.title,
validator: RequiredValidator(
errorText:
"This field can't be empty"),
onChanged: (value) => _activity.value =
_activity.value
.copyWith(title: value),
),
SizedBox(
height: 5,
),
Field(
label: "Description of Activity",
iconData: Icons.description,
validator: RequiredValidator(
errorText:
"This field can't be empty"),
onChanged: (value) => _activity.value =
_activity.value
.copyWith(description: value),
),
Align(
alignment: Alignment.center,
child: TextButton(
child: Icon(Icons.camera),
onPressed: () async {
String imageid = uuid.v4();
pickedImage = await ImagePicker()
.getImage(
source: ImageSource.gallery,
maxWidth: 1920,
maxHeight: 1200,
imageQuality: 80);
Reference reference = FirebaseStorage
.instance
.ref()
.child("$imageid");
UploadTask uploadTask = reference
.putFile(File(pickedImage.path));
await uploadTask.then((res) async {
imageUrl = await reference
.getDownloadURL();
});
_activity.value = _activity.value
.copyWith(picture: imageUrl);
},
),
),
GestureDetector(
onTap: () async {
_activity.value= _activity.value.copyWith(id:uuid.v4());
_activity.value = _activity.value.copyWith(avatar:org.picture);
context
.read(createActivityUSeCaseProvider)
.execute(CreateActivityUseCaseInput(
model: _activity.value
))
.then(
(result) => result.fold(
(failure) {
print('FAILURE: $failure');
toast("Please try again");
},
(unit) {
print(_activity.value);
Navigator.of(context).pop();
toast(" Successful ");
},
),
);
},
child: Container(
height: 80.0,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.black38),
child: Text('Post',
style: TextStyle(
color: Colors.white70,
letterSpacing: 1.5,
fontSize: 22.0,
fontWeight: FontWeight.w600)),
),
),
],
),
)),
);
});
},
),
loading: () => const CircularProgressIndicator(),
error: (error, stack) => Center(
child: Text("$error"),
))
: null,
);
}
}
但问题是每当我打印它的值时,它都不为空并且所有值都被占用