0

我已经看到了很多关于这个主题的讨论,但还没有为我的问题找到合适的解决方案。

我想要实现的是Process.id从 ListView 传递到第二个小部件,然后在第二个小部件中 - 从 SQLite 加载对象并用Process数据更新 Scaffold 中的其他小部件。

我已经设法做到了(部分),因为我正在努力将数据加载到 ListView 小部件(我必须解析 json String 以创建 List,然后每当我尝试使用 List 更新 ListView.builder -我得到空白屏幕和异常)。注释掉 ListView.builder - 小部件工作正常......可能我将代码放在错误的位置......

这就是我的代码的样子:

  1. 从Widget 1Process.id中的 ListView传递...

    ...
    return new ListTile(
         onTap: () {
         Navigator.push(
            context, 
            MaterialPageRoute(builder: (context) => ScreenProcessDetails(processId: _newProcesses[index].id)));}, 
    ...
    

    小部件 2 ->完成:

    class ScreenProcessDetails extends StatefulWidget {
        final int processId;
    
        ScreenProcessDetails({Key key, @required this.processId}) : super(key: key);
    
        @override
            State createState() {
            return new _ScreenProcessDetailsState();
        }
    }
    
  2. 在Widget 的 2 -> DONE 中从 SQLite加载Process对象(使用 SQFlite),如下所示: ScreenProcessDetails initState()

    class _ScreenProcessDetailsState extends State<ScreenProcessDetails> {
        Process process;
    
        Future<Process> getProcess(int id) async {
            process = await _repository.getProcess(id);
            setState(() {
            });
        }
    
        @override
        void initState() {
          super.initState();
          getProcess(widget.processId);
        }
    
        @override
        Widget build(BuildContext context) {
        String defaultValue = process.defaultValue;
        List<dynamic> filesJson = jsonDecode(process.files);
        filesList = filesJson.map((i) => new Files.fromJson(i)).toList();
    
            return new Scaffold(
              appBar: new AppBar(title: new Text(process.name)),
              body: Builder (builder: (context) => new Container(
                    child: new Column(
                      children: <Widget>[
                        new Text(process.name),
                        new TextFormField(initialValue: defaultValue,),
                        new ListView.builder(
                          physics: const NeverScrollableScrollPhysics(),
                          itemCount: filesList.length,
                          itemBuilder: (context, int index) {
                            return new ListTile(
                              leading: new Icon(Icons.archive, color: Colors.amber),
                              title: new Text(filesList[index].name),
                              subtitle: new Text(filesList[index].guid),
                              );
                          })
        //skipped rest of code 
    }
    

但是filesList 没有加载- 整个屏幕都是白色的,我正在获取异常列表(如下)。我想知道我可能做错了什么?我已经尝试过使用String我的对象的 instedProcess没有运气。

还有一件事 - 我的意思是从 SQLiteinitState()正确加载对象吗?因为我看到一个例外:

2019-02-20 13:02:13.023 19208-19288/pl.itelix.documentapp I/flutter: Another exception was thrown: NoSuchMethodError: The getter 'name' was called on null.

这(据我了解)意味着该对象为空......但整个小部件是正确构建的?!

或者我应该使用加载 SQLite 数据Future然后开始加载整个小部件树?还有一件事——我尝试使用 FutureBuilder,但每次我尝试在 TextField 中输入文本时都会重新创建它。

例外:

2019-02-20 12:41:07.490 19208-19288/documentapp I/flutter: Another exception was thrown: Vertical viewport was given unbounded height.
2019-02-20 12:41:07.492 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#627ff NEEDS-LAYOUT NEEDS-PAINT
2019-02-20 12:41:07.493 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#627ff NEEDS-PAINT
2019-02-20 12:41:07.496 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#e5843 relayoutBoundary=up26 NEEDS-PAINT
2019-02-20 12:41:07.500 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#bb781 relayoutBoundary=up25 NEEDS-PAINT
2019-02-20 12:41:07.502 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#57754 relayoutBoundary=up24 NEEDS-PAINT
2019-02-20 12:41:07.503 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#54f57 relayoutBoundary=up23 NEEDS-PAINT
2019-02-20 12:41:07.505 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#1370c relayoutBoundary=up22 NEEDS-PAINT
2019-02-20 12:41:07.507 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#c4b4e relayoutBoundary=up21 NEEDS-PAINT
2019-02-20 12:41:07.508 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#88d67 relayoutBoundary=up20 NEEDS-PAINT
2019-02-20 12:41:07.510 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#b4040 relayoutBoundary=up19 NEEDS-PAINT
2019-02-20 12:41:07.511 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#09183 relayoutBoundary=up18 NEEDS-PAINT
2019-02-20 12:41:07.513 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#50678 relayoutBoundary=up17 NEEDS-PAINT
2019-02-20 12:41:07.515 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: _RenderInkFeatures#de7b5 relayoutBoundary=up16 NEEDS-PAINT
2019-02-20 12:41:07.517 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#05457 relayoutBoundary=up15 NEEDS-PAINT
2019-02-20 12:41:07.519 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#2b262 relayoutBoundary=up14 NEEDS-PAINT
2019-02-20 12:41:07.520 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#5eb3c relayoutBoundary=up13 NEEDS-PAINT
2019-02-20 12:41:07.522 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#e3fcc relayoutBoundary=up12 NEEDS-PAINT
2019-02-20 12:41:07.524 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#8eaef relayoutBoundary=up11 NEEDS-PAINT
2019-02-20 12:41:07.525 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: _RenderSingleChildViewport#c3635 relayoutBoundary=up10 NEEDS-PAINT
2019-02-20 12:41:07.526 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#c220a relayoutBoundary=up9 NEEDS-PAINT
2019-02-20 12:41:07.529 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#bf875 relayoutBoundary=up8 NEEDS-PAINT
2019-02-20 12:41:07.530 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#789f6 relayoutBoundary=up7 NEEDS-PAINT
2019-02-20 12:41:07.532 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#cabf4 relayoutBoundary=up6 NEEDS-PAINT
2019-02-20 12:41:07.533 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#8ab03 relayoutBoundary=up5 NEEDS-PAINT
2019-02-20 12:41:07.535 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#274a1 relayoutBoundary=up4 NEEDS-PAINT
2019-02-20 12:41:07.536 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#6174f relayoutBoundary=up3 NEEDS-PAINT
2019-02-20 12:41:07.538 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#a452d relayoutBoundary=up2 NEEDS-PAINT
2019-02-20 12:41:07.539 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#8c834 relayoutBoundary=up1 NEEDS-PAINT
2019-02-20 12:41:07.543 19208-19288/documentapp I/flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#a452d relayoutBoundary=up2 NEEDS-PAINT

非常感谢任何帮助!先感谢您!:)

4

1 回答 1

0

发现问题 - 列中的 ListView 必须包含在 Flex/Extended 小部件中。

于 2019-02-22T08:58:33.203 回答