我可以在无状态小部件中使用GestureDetector
。
我正在尝试在状态完整的小部件中使用更复杂的代码,并得到只能访问静态成员的错误。
我假设一些简单的代码。
删除GestureDetector
和代码即可。
Navigator.of(context).pushNamed('/google');
上下文是我得到错误的地方。
import 'package:flutter/material.dart';
import 'package:liquid_swipe/liquid_swipe.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
String google = 'https://www.google.com/';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final textController = TextEditingController();
final webview = FlutterWebviewPlugin();
TextEditingController controller = TextEditingController(text: google);
final pages = [
Container(
height: double.maxFinite,
color: Colors.blue[600],
child: SingleChildScrollView(
padding: EdgeInsets.fromLTRB(0, 100, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
'assets/1.png',
fit: BoxFit.cover,
),
Padding(padding: const EdgeInsets.all(20.0)),
Column(
children: <Widget>[
new Text(
"Google",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/google');
new Text(
"Login",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
);
},
),
],
)
],
),
)
),
Container(
color: Colors.pink,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
'assets/1.png',
fit: BoxFit.cover,
),
Padding(padding: const EdgeInsets.all(20.0)),
Column(
children: <Widget>[
new Text(
"Liked?",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Fork!",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Give Star!",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
],
)
],
),
),
Container(
color: Colors.greenAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
'assets/1.png',
fit: BoxFit.cover,
),
Padding(padding: const EdgeInsets.all(20.0)),
Column(
children: <Widget>[
new Text(
"Liked?",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Fork!",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Give Star!",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
],
)
],
),
),
Container(
color: Colors.yellowAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
'assets/1.png',
fit: BoxFit.cover,
),
Padding(padding: const EdgeInsets.all(20.0)),
Column(
children: <Widget>[
new Text(
"Can be",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Used for",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Onboarding Design",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
],
)
],
),
),
Container(
color: Colors.redAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
'assets/1.png',
fit: BoxFit.cover,
),
Padding(padding: const EdgeInsets.all(20.0)),
Column(
children: <Widget>[
new Text(
"Do",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Try it",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
new Text(
"Thank You",
style: TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600),
),
],
)
],
),
),
];
@override
void initState() {
super.initState();
webview.close();
controller.addListener(() {
google = controller.text;
});
}
@override
void dispose() {
webview.dispose();
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
routes: {
"/google": (_) => WebviewScaffold(
url: google,
appBar: AppBar(
title: Text("Google"),
backgroundColor: Color.fromRGBO(0x00, 0x6e, 0xa1, 1.0),
),
withJavascript: true,
withLocalStorage: true,
withZoom: true,
),
},
home: new Scaffold(
body: LiquidSwipe(
pages: pages,
fullTransitionValue: 500,
enableSlideIcon: true,
),
));
}
}
void main() {
runApp(MyApp());
}
我正在尝试获取来自GestureDetector
的网页视图。