Flutter:重置或退出应用程序时不保留列表状态

时间:2020-01-11 08:52:39

标签: flutter dart state

因此,我正在编写一个提醒应用程序,该应用程序使用sliverchildbuilderdelegate构建列表。但是,每当我退出或重置应用程序时,该列表就会消失,并从索引0重新开始。代码如下:

class RemindersScreen extends StatefulWidget {
  @override
  _RemindersScreenState createState() => _RemindersScreenState();
}

class _RemindersScreenState extends State<RemindersScreen>{
  @override
  void initState() {
    super.initState();
  }

SliverList(
 delegate: SliverChildBuilderDelegate((BuildContext context, int id){
 return Card(
  elevation: 10.0,
  color: Color(0xff424242),
  child: ListTile(
   trailing: IconButton(
    onPressed: (){
     print('Test');
    },
    icon: Icon(
    Icons.delete,
    color: Colors.white,
    size: 30.0, 
   ),
  ),
  contentPadding: EdgeInsets.all(20.0),
  title: Text(
   notifications[id].title,
   style: TextStyle(
    color: Colors.white,
     fontSize: 25.0,
     fontWeight: FontWeight.w700,
    ),
   ),
   subtitle: AutoSizeText(
    DateFormat.yMMMMEEEEd().add_jm().format(notifications[id].scheduledDate),
    maxLines: 1,
    style: TextStyle(
     color: Colors.white38,
    ),
   ),
  ),
 );
},
childCount: notifications.length,
),
),

@override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return platformScaffoldReminder(context);
  }

我知道AutomaticKeepAliveClientMixin,但是我不确定如何将其应用于我的代码。任何帮助将不胜感激。谢谢。

0 个答案:

没有答案