首页 > 解决方案 > 如何将数据传递给颤振应用程序中的类

问题描述

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

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

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

我尝试遵循方法,但 ity 不起作用。这是我的 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'))));
              },
            );
          }),
    );
  }
}

标签: flutter

解决方案


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


推荐阅读