【问题标题】:How to pass data to a class in a flutter app如何将数据传递给颤振应用程序中的类
【发布时间】:2021-08-08 23:53:29
【问题描述】:

我正在尝试将数据传递给 Flutter 中的类,但由于此错误而失败,我不知道如何调试它,我是 Flutter 的新手:

errors.dart:187 Uncaught (in promise) 错误:无效参数:未找到提要

我怎么知道它找不到哪个提要?

我尝试关注this,但它无法正常工作。这是我的 main.dart 代码:

void main() async {
   final AtomFeed feed = await RssService().getFeed();
  runApp(Start(feed));
}

class Start extends StatelessWidget {

  final AtomFeed feed;

  Start(this.feed);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 5,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(text: 'First', icon: Icon(Icons.music_note)),
                Tab(text: 'Second', icon: Icon(Icons.music_video)),
              ],
            ),
            title: Text('Start'),
            backgroundColor: Colors.green,
          ),
          body: TabBarView(
            children: [
              First(this.feed),
              MyHomePage(title: 'Wowzers!'),
            ],
          ),
        ),
      ),
    );
  }
}

然后在第一个:

class First extends StatelessWidget {
  final AtomFeed feed;

  First(this.feed);

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('RSS'),
      ),
      body: ListView.builder(
          itemCount: this.feed.items.length,
          itemBuilder: (BuildContext ctxt, int index) {
            final item = this.feed.items[index];
            return ListTile(
              title: Text(item.title),
              subtitle: Text('Published at ' +
                  DateFormat.yMd().format(DateTime.parse(item.published))),
              contentPadding: EdgeInsets.all(16.0),
              onTap: () async {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => WebViewContainer(
                            item.id.replaceFirst('http', 'https'))));
              },
            );
          }),
    );
  }
}

【问题讨论】:

  • 您是否使用热重载/热重启?您是否尝试过完全停止并重新运行您的应用?
  • @Naslausky 是的。我已经关闭并重新打开了 VS 代码。

标签: flutter


【解决方案1】:

我将所有 feed 变量重命名为 feed1、feed2 等。问题不在于我的任何变量,而在于 rss 服务的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 2020-02-13
    • 2021-01-03
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多