我们如何将模型数据存储到 flutter 安全存储中……或者它支持吗?
我有一个这样的模型...我将数据从我的 API 加载到这个模型...一旦我有了数据,我想将其保存到 flutter 安全存储中,反之亦然(将整个数据从 flutter 安全存储加载到模型中) ...
class MyUserModel {
MyUserModel({
this.authKey,
this.city,
this.contact,
this.email,
this.isContact,
this.userId,
});
String authKey;
String city;
String contact;
dynamic email;
bool isContact;
int userId;
}
Run Code Online (Sandbox Code Playgroud)
当然,我知道我们可以像下面这样读取和写入数据...我只是检查是否有一种方法可以直接从模型写入数据...
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
// Create storage
final storage = new FlutterSecureStorage();
// Read value
String value = await storage.read(key: key);
// Write value
await storage.write(key: key, value: value);
Run Code Online (Sandbox Code Playgroud)
我看到 hive 开箱即用地支持此功能,但我意识到初始化也只需要很少的时间(2-3 秒)作者正在研究 hive 的替代方案,因为有两个主要块......名为Isar的新数据库可以清除所有障碍,但它仍在开发中......
如果可能的话请分享示例代码...
如何验证电子邮件或电话的相同字段或不为空?
TextFormField(
// validator: ???,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(16.0),
hintText: "hint_phone_no_email_address",
filled: true,
fillColor: Colors.grey.withOpacity(0.1),
),
),
Run Code Online (Sandbox Code Playgroud)
我想在按下按钮时进行验证
RaisedButton(
onPressed: () {
// call validate function from here.....
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF0D47A1),
Color(0xFF1976D2),
Color(0xFF42A5F5),
],
),
),
child:
Text('Next', style: TextStyle(fontSize: 20)),
),
),
Run Code Online (Sandbox Code Playgroud)
请告诉我...