I registerd model.dart / model.g.dart also opened box in main(). I just only want to put value on 'userName', don't want effect other key/ value but how?
on main
thank you.
CodePudding user response:
to do this u will have to first get the object for the model as based on your criteria this object already exists with different data!.
u can create a copyWith fn in your Model to mutate the object(clone).
u can achieve this using something as follows
final box = await Hive.openBox('db');
// the returned value can be null here, i assumed that the data already exists
final existingValue = box.get('userName');
await box.put('userName', existingValue.copyWith(userName: textController.text));
CodePudding user response:
The answer M Afzal gave should work. However, your onPressed() is async which might be why you are getting the undefined Future error. https://dart.dev/codelabs/async-await