小编Far*_*DIN的帖子

我想要第一个 ExpansionTile 的项目默认是打开的。我想当我单击另一个项目时,当前项目将关闭。我该怎么做?

 body: Container(color: Colors.white,
          child: SingleChildScrollView(
              child : Column( 
                children : [
                  Padding(padding: EdgeInsets.only(left : 23.0, top: 23.0, right: 23.0, bottom: 5.0), 
                              child : Text("Title", style: MyTextStyles.textNormal,)),

                  ListView.builder(
                      padding: EdgeInsets.only(left: 13.0, right: 13.0, bottom: 25.0),
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: PersonModel.icData.length,
                      itemBuilder: (context, index) {
                        PersonModel _model = PersonModel.icData[index];
                        return Column(
                          children: <Widget>[
                            Divider(
                              height: 17.0,
                              color: MyColors.white,
                            ), 
                                  ExpansionTile(
                                        key:  PageStorageKey<String>(index.toString()),
                                        initiallyExpanded: false,
                                        leading: 
                                        new ClipOval(
                                                child: SvgPicture.asset(
                                                    _model.picture,
                                                    height: 57.0,
                                                    width: 57.0,
                                                ),
                                            ),

                                        title: Text(_model.title,style: TextStyle(color: Color(0xFF09216B), fontFamily: …
Run Code Online (Sandbox Code Playgroud)

expansion dart flutter flutter-layout flutter-animation

5
推荐指数
1
解决办法
1万
查看次数

Flutter - 提供者 - 在构建期间调用 setstate 或 markneedsbuild()

我有一个 Flutter 项目。我正在使用 Provider (4.0.5) 进行状态管理。我收到此警告,“在构建过程中调用了 setstate 或 markneedsbuild()” 这对我来说是个大问题。我认为这个问题会在发布模式下增长。我该如何解决这个问题?

import 'package:example/models/notebook_model.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class NotebookState with ChangeNotifier {

  DateTime notebookDate = DateTime.now();

  DateTime notebookDateState(DateTime date){
     notebookDate = date;
     notifyListeners();
     return notebookDate;
  }

  Future<List<NotebookModel>> getNotebook()
  {
    notifyListeners();
    return NotebookBLL.getNotebooks();
  }

  addNotebook(String noteTitle, String content, String date){
    NotebookModel newNotebook = NotebookModel(
        noteTitle: noteTitle, content: content, date: date);

    NotebookBLL.insert(newNotebook);

    notifyListeners();                    
  }

  updateNotebook(int id, String noteTitle, String content, String date){
    NotebookModel updateNotebook = NotebookModel(
      id: id,
      noteTitle: noteTitle,
      content: content,
      date: …
Run Code Online (Sandbox Code Playgroud)

provider state setstate flutter flutter-layout

1
推荐指数
1
解决办法
4988
查看次数