Flutter WEb:NoSuchMetodError:尝试调用修女函数:例如 null;易网开发

发布于 2025-01-14 02:11:09 字数 4173 浏览 2 评论 0原文

我正在努力在网络版本中实现 flutter 的 easyweb 包 所以基本上我已经下载并添加了依赖项,并且创建了仅与 Easy Web 相关的特定类 我的 Easy Web 小部件如下所示。我的目标是当用户单击主页选项卡时使外部网站出现在网站的主页上。

import 'package:easy_web_view/easy_web_view.dart';
import 'package:flutter/material.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen();
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  String src = 'https://flutter.dev/';
  bool _isHtml = false;
  bool _isMarkdown = false;
  bool _useWidgets = false;
  bool _editing = false;

  @override
  Widget build(BuildContext context) {

      return Column(
        children: <Widget>[
        SizedBox(
        height: 120.0, //450
      ),
      IconButton(
        icon: Icon(_editing ? Icons.close : Icons.settings),
        onPressed: () {
          if (mounted)
            setState(() {
              _editing = !_editing;
            });
        },
      ),

      SizedBox(
        height: 5.0,
      ),
        Container(
        height: MediaQuery.of(context).size.height*1.90,
        width: MediaQuery.of(context).size.width*0.40,
        child: Card(
        elevation: 5.0,
        color: Colors.transparent,
        //shadowColor: Color(0xFF032539),
        shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20),
        ),
        child: _editing
        ? SingleChildScrollView(
        child: Column(
        children: <Widget>[
        SwitchListTile(
        title: Text('Html Content'),
        value: _isHtml,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _isHtml = val;
        if (val) {
        _isMarkdown = false;
        src = htmlContent;
        } else {
        src = url;
        }
        });
        },
        ),
        SwitchListTile(
        title: Text('Markdown Content'),
        value: _isMarkdown,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _isMarkdown = val;
        if (val) {
        _isHtml = false;
        src = markdownContent;
        } else {
        src = url;
        }
        });
        },
        ),
        SwitchListTile(
        title: Text('Use Widgets'),
        value: _useWidgets,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _useWidgets = val;
        });
        },
        ),
        ],
        ),
        )
            : EasyWebView(
        src: src,
        isHtml: _isHtml,
        isMarkdown: _isMarkdown,
        convertToWidgets: _useWidgets,
        //width: 100,
        //height: 100,
        ),
        ),
        ),
        ],
      );





  }

  String get htmlContent => """
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
""";

  String get markdownContent => """
# This is a heading

## Here's a smaller heading

This is a paragraph

* Here's a bulleted list
* Another item

1. And an ordered list
1. The numbers don't matter

> This is a qoute

[This is a link to Flutter](https://flutter.dev)
""";

  String get embeedHtml => """
<iframe width="560" height="315" src="https://flutter.dev" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
""";

  String get url => 'https://flutter.dev';
}

所以基本上当用户单击时在主页选项卡中我想显示外部网站的内容

但它给了我这样的错误NoSuchMetodError:试图调用一个修女函数:例如null 'this.widget.onLoaded':

有谁知道我在哪里犯了错误?我是 flutter 新手,这就是为什么我无法弄清楚我在哪里犯了错误,

我在调试模式下运行代码,它给了我以下错误的详细信息

这里说的是Bug是由Card widget引起的

这里据说参数“onLoaded”是必需的,正如您在 Dart 分析部分的最下面看到的那样

正如我提到的,我是 flutter 的新手,我不知道在哪里放置该 onladed 方法

如果有人知道的话,那真的是如果你能告诉我那就太好了

谢谢你的帮助 干杯

I am struggling here with implementing easyweb package of flutter in web version
so basically I have downloaded and added the dependencies and I created specific class only related to easy web My widget of easy web look like this. And my goal was to make external website appear on the Main page of the website when user will click home tab.

import 'package:easy_web_view/easy_web_view.dart';
import 'package:flutter/material.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen();
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  String src = 'https://flutter.dev/';
  bool _isHtml = false;
  bool _isMarkdown = false;
  bool _useWidgets = false;
  bool _editing = false;

  @override
  Widget build(BuildContext context) {

      return Column(
        children: <Widget>[
        SizedBox(
        height: 120.0, //450
      ),
      IconButton(
        icon: Icon(_editing ? Icons.close : Icons.settings),
        onPressed: () {
          if (mounted)
            setState(() {
              _editing = !_editing;
            });
        },
      ),

      SizedBox(
        height: 5.0,
      ),
        Container(
        height: MediaQuery.of(context).size.height*1.90,
        width: MediaQuery.of(context).size.width*0.40,
        child: Card(
        elevation: 5.0,
        color: Colors.transparent,
        //shadowColor: Color(0xFF032539),
        shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20),
        ),
        child: _editing
        ? SingleChildScrollView(
        child: Column(
        children: <Widget>[
        SwitchListTile(
        title: Text('Html Content'),
        value: _isHtml,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _isHtml = val;
        if (val) {
        _isMarkdown = false;
        src = htmlContent;
        } else {
        src = url;
        }
        });
        },
        ),
        SwitchListTile(
        title: Text('Markdown Content'),
        value: _isMarkdown,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _isMarkdown = val;
        if (val) {
        _isHtml = false;
        src = markdownContent;
        } else {
        src = url;
        }
        });
        },
        ),
        SwitchListTile(
        title: Text('Use Widgets'),
        value: _useWidgets,
        onChanged: (val) {
        if (mounted)
        setState(() {
        _useWidgets = val;
        });
        },
        ),
        ],
        ),
        )
            : EasyWebView(
        src: src,
        isHtml: _isHtml,
        isMarkdown: _isMarkdown,
        convertToWidgets: _useWidgets,
        //width: 100,
        //height: 100,
        ),
        ),
        ),
        ],
      );





  }

  String get htmlContent => """
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
""";

  String get markdownContent => """
# This is a heading

## Here's a smaller heading

This is a paragraph

* Here's a bulleted list
* Another item

1. And an ordered list
1. The numbers don't matter

> This is a qoute

[This is a link to Flutter](https://flutter.dev)
""";

  String get embeedHtml => """
<iframe width="560" height="315" src="https://flutter.dev" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
""";

  String get url => 'https://flutter.dev';
}

So basically here in home tab when user click I would like to show the content of the external website

but it is giving me eror like this NoSuchMetodError: tried to call a nun-function:such as null 'this.widget.onLoaded':

Does anyone know where I am making mistake? I am new in flutter and thats why I couldnt figure out where I am making mistake

I run the code with debug mode and it gave me following details of the bug

Here it is saying that the bug was caused by Card widget

And here it is saying that the parameter "onLoaded" is required as you can see in the very down in Dart analysis section

As I mentioned I am new to flutter Idont know whaere to put that onladed method

If someone knows it would be really great if you can tell me

Thank you for your help
Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2025-01-21 02:11:09

您是否尝试过以调试模式运行它?因为有时我可以通过使用调试模式运行它而不是在终端中使用“flutter run”来理解为什么会出现错误。

Did you tried to run this with debug mode? Because sometimes i can understand why i am having an error by running it with debug mode rather than using "flutter run" in terminal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文