身体可能正常完成,导致' null'要返回,但是返回类型,state< statefulwidget>'''

发布于 2025-01-25 01:59:43 字数 2186 浏览 3 评论 0原文

我是新来的颤抖。我试图构建一个具有令牌的网络浏览量。我已经使用了状态窗口小部件,但我面临此错误 身体可能正常完成,导致“ null”返回,但返回类型“状态”是一种潜在的不可努力的类型。 代码:

    import 'dart:async';

    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    import 'package:flutter_form_bloc/flutter_form_bloc.dart';
    import 'package:maze/authentication/bloc/authentication_bloc.dart';
    import 'package:maze/core/drawer.dart';
    import 'package:webview_flutter/webview_flutter.dart';

    import '../../authentication/bloc/authentication_state.dart';
    import '../../core/secure_store.dart';

    class ProfileView extends StatefulWidget {
     @override
     State<StatefulWidget> createState() {
     ProfileViewState createState() =>ProfileViewState();

     }

    }
    class ProfileViewState extends State<ProfileView> {
     build(BuildContext context) async {
    var state = BlocProvider
        .of<AuthenticationBloc>(context)
        .state;
    var token = await SecureStore().credentials;

    final Completer<WebViewController> _controller =
    Completer<WebViewController>();

    return Scaffold(
      appBar: AppBar(
        title: const Text('Profile'),
        actions: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Align(
              child: Text("name",
                  style: new TextStyle(fontWeight: FontWeight.bold)),
              alignment: Alignment.bottomCenter,
            ),
          ),
        ],
      ),
      drawer: const CustomDrawer(),
      body: BlocBuilder<AuthenticationBloc, AuthenticationState>(
        builder: (context, state) {
          return Center(
              child: WebView(
                javascriptMode: JavascriptMode.unrestricted,

                onWebViewCreated: (WebViewController webViewController{
                  webViewController.loadUrl(
                      "http:exemple...",
                      headers: {"Authorization": "Bearer ${token}"});
                  _controller.complete(webViewController);
                },
              )
          );
        },
      ),
    );
  }

}

I'm new in flutter. I tried to build a webview that have a token. I have used statefull widget but I am facing this error
The body might complete normally, causing 'null' to be returned, but the return type, 'State', is a potentially non-nullable type.
The code:

    import 'dart:async';

    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    import 'package:flutter_form_bloc/flutter_form_bloc.dart';
    import 'package:maze/authentication/bloc/authentication_bloc.dart';
    import 'package:maze/core/drawer.dart';
    import 'package:webview_flutter/webview_flutter.dart';

    import '../../authentication/bloc/authentication_state.dart';
    import '../../core/secure_store.dart';

    class ProfileView extends StatefulWidget {
     @override
     State<StatefulWidget> createState() {
     ProfileViewState createState() =>ProfileViewState();

     }

    }
    class ProfileViewState extends State<ProfileView> {
     build(BuildContext context) async {
    var state = BlocProvider
        .of<AuthenticationBloc>(context)
        .state;
    var token = await SecureStore().credentials;

    final Completer<WebViewController> _controller =
    Completer<WebViewController>();

    return Scaffold(
      appBar: AppBar(
        title: const Text('Profile'),
        actions: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Align(
              child: Text("name",
                  style: new TextStyle(fontWeight: FontWeight.bold)),
              alignment: Alignment.bottomCenter,
            ),
          ),
        ],
      ),
      drawer: const CustomDrawer(),
      body: BlocBuilder<AuthenticationBloc, AuthenticationState>(
        builder: (context, state) {
          return Center(
              child: WebView(
                javascriptMode: JavascriptMode.unrestricted,

                onWebViewCreated: (WebViewController webViewController{
                  webViewController.loadUrl(
                      "http:exemple...",
                      headers: {"Authorization": "Bearer ${token}"});
                  _controller.complete(webViewController);
                },
              )
          );
        },
      ),
    );
  }

}

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

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

发布评论

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

评论(2

予囚 2025-02-01 01:59:43

更改您的createState方法:从此

class ProfileView extends StatefulWidget {
 @override
 State<StatefulWidget> createState() {
 ProfileViewState createState() =>ProfileViewState();

 }

}

class ProfileView extends StatefulWidget {
 @override
 State<ProfileView> createState() => ProfileViewState();
}

Change your createState method from this:

class ProfileView extends StatefulWidget {
 @override
 State<StatefulWidget> createState() {
 ProfileViewState createState() =>ProfileViewState();

 }

}

To this:

class ProfileView extends StatefulWidget {
 @override
 State<ProfileView> createState() => ProfileViewState();
}
江南烟雨〆相思醉 2025-02-01 01:59:43

按照以下代码更新您的个人资料视图类:

    class ProfileView extends StatefulWidget {
     @override
     State<ProfileView> createState() =>ProfileViewState();

    }

您的错误重复了CreateState()行两次。

Update your profile view class like the below code:

    class ProfileView extends StatefulWidget {
     @override
     State<ProfileView> createState() =>ProfileViewState();

    }

Your have by mistake repeated the createState() line two times.

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