身体可能正常完成,导致' null'要返回,但是返回类型,state< statefulwidget>'''
我是新来的颤抖。我试图构建一个具有令牌的网络浏览量。我已经使用了状态窗口小部件,但我面临此错误 身体可能正常完成,导致“ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改您的
createState
方法:从此:
Change your
createState
method from this:To this:
按照以下代码更新您的个人资料视图类:
您的错误重复了CreateState()行两次。
Update your profile view class like the below code:
Your have by mistake repeated the createState() line two times.