Change the boolean value onclick and save to secured storage flutter - flutter

class Lessons {
final int? id;
final String? title;
final List<Resources> resources;
Lessons({
required this.id,
required this.title,
required this.resources,
});
}
class Resources extends Equatable {
final int? id;
final String? question;
final String? answer;
bool? bookmark;
Resources({
required this.id,
required this.question,
required this.answer,
required this.bookmark,
});
}
-these are my models, and have saved them using the secured storage flutter. How do i change just the bookmark and save it to secured storage?
i was able to change the bookmark but was unable to save it dynamically to secured storage.

Related

How to generate file from model to flutter

Is it possible to convert the Model to a file and save it in the phone's storage? When it comes to non-standard variables String, int, bool... I mean there are variables that can't be converted to json.
This is my model:
class TronWalletModel {
final List<String> mnemonic;
final Uint8List seed;
final PrivateKey privateKey;
final PublicKey publicKey;
final String address;
final Uint8List signature;
TronWalletModel({
required this.mnemonic,
required this.seed,
required this.privateKey,
required this.publicKey,
required this.address,
required this.signature,
});
}
How can I save it to the phone's storage?

flutter Erorr I cant deal with

I tried making a class then making a list of that class and I get an Erorr
the class I created:
class Transaction {
final String id;
final String title;
final double amount;
final DateTime date;
Transaction({
required this.id,
required this.title,
required this.amount,
required this.date,
});
}
Erorrs I get :
Try changing your variable name as it is clashing with the class name Transaction
and you can also use a different approach:
final List<Transaction>? transactionList;
trnasactionList.add(Transaction(id:1,title:'flutter' ....));
trnasactionList.add(Transaction(id:2,title:'flutter' ....));

List, verify register flutter

hello I am new to flutter and programming, if anyone can help me this is my question
I have one class with multiple products and I need to verify if they are in BD. So this is the class of products:
class CartItem {
final String name;
final double price;
final double quantity;
final String image;
final String cor;
final String tamanho;
CartItem({
required this.name,
required this.price,
required this.quantity,
required this.image,
required this.cor,
required this.tamanho,
});
}
And this is the URL to receive a true or false value depending on whether the product is in the BD or not
http://tzev.ddns/PTTC.1/PTTCProd?Stock=True&Reference=&Color=&Size=
First I have to store the value of the reference in the class, but then I don't know how to read one by one to receive the various values ​​of the API call

how to solve flutter null value issue in my code?

I want to keep null as a default value for product id, as it'll be later auto-generated, but I can't due to the flutter null safety check.
this is the instance creation code where I want to keep id = null:
var _editedProduct = Product(
id: null,
title: '',
price: 0,
description: '',
imageUrl: '',
);
and here is the code for my Product.dart file:
import 'package:flutter/material.dart';
class Product with ChangeNotifier {
final String id;
final String title;
final String description;
final double price;
final String imageUrl;
bool isFavorite;
Product({
required this.id,
required this.title,
required this.description,
required this.price,
required this.imageUrl,
this.isFavorite = false,
});
void toggleFavoriteStatus() {
isFavorite = !isFavorite;
notifyListeners();
}
}
A screenshot of the error
While you like to have id default value as null, First you need to accept nullable data. For final String id; will be final String? id; the default value can be provided on constructor by removing required to act as optional. id will have null by default.
To use id you need to check if it is null or not.
If you are sure it contains data use ! at the end like id!, or
provide a default value like id??"default", or
if(Product.id!=null){...}
class Product with ChangeNotifier {
final String? id;
final String title;
final String description;
final double price;
final String imageUrl;
bool isFavorite;
Product({
this.id,
required this.title,
required this.description,
required this.price,
required this.imageUrl,
this.isFavorite = false,
});
...
Learn more about null-safety
Following changes solved my issue:
changing final String id; to final String? id; in Product.dart
changing final productId = ModalRoute.of(context)!.settings.arguments as String; to final String? productId = ModalRoute.of(context)!.settings.arguments as String?;

What is the right function to add persons number to my cooking app?

import 'package:flutter/foundation.dart';
enum Complexity {
Simple,
Challenging,
Hard,
}
class Meal {
final String id;
final List<String> categories;
final String title;
final String imageUrl;
final List<String> ingredients;
final List<String> steps;
final int duration;
final Complexity complexity;
final bool isGlutenFree;
final bool isLactoseFree;
final bool isVegan;
final bool isVegetarian;
const Meal({
required this.id,
required this.categories,
required this.title,
required this.imageUrl,
required this.ingredients,
required this.steps,
required this.duration,
required this.complexity,
required this.isGlutenFree,
required this.isLactoseFree,
required this.isVegan,
required this.isVegetarian,
});
}
Hallo, i have added the complexity of my meals to my meal app.
But, how can I add the number of persons? What do I need? I want to add, that the meal is for 1 or 2 or 3 persons.
Thank you!