我有100个要做的复选框,我想保存其状态。因此,重新启动后该值应该存在。 有没有简单的方法。
下面是我目前正在处理的事情。
import 'package:flutter/material.dart';
void main(){
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => new _State();
}
//State is information of the application that can change over time or when some actions are taken.
class _State extends State<MyApp>{
bool _value1 = false;
bool _value2 = false;
//we omitted the brackets '{}' and are using fat arrow '=>' instead, this is dart syntax
void _value1Changed(bool value) => setState(() => _value1 = value);
void _value2Changed(bool value) => setState(() => _value2 = value);
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Name here'),
),
//hit Ctrl+space in intellij to know what are the options you can use in flutter widgets
body: new Container(
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Column(
children: <Widget>[
new CheckboxListTile(
value: _value2,
onChanged: _value2Changed,
title: new Text('Check box 1'),
controlAffinity: ListTileControlAffinity.leading,
subtitle: new Text('100th'),
secondary: new Icon(Icons.archive),
activeColor: Colors.red,
),
new CheckboxListTile(
value: _value2,
onChanged: _value2Changed,
title: new Text('Check box 2'),
controlAffinity: ListTileControlAffinity.leading,
subtitle: new Text('99th'),
secondary: new Icon(Icons.archive),
activeColor: Colors.red,
),
],
),
),
),
);
}
}
快速的棕色狐狸跳过懒惰的狗快速的棕色狐狸跳过懒惰的狗快速的棕色狐狸跳过懒惰的狗快速的棕色狐狸跳过懒惰的狗快速的棕色狐狸跳过懒惰的狗