【发布时间】:2020-08-08 17:28:13
【问题描述】:
我从这里https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html阅读了有关 InteractiveViewer 的信息
但是当我尝试在我的代码中使用 InteractiveViewer 时,它给了我一个错误:-
The method 'InteractiveViewer' isn't defined for the type 'MyHomeState'.
Try correcting the name to the name of an existing method, or defining a method named
'InteractiveViewer'.dartundefined_method
我的颤振代码如下:-
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static const String _title = "InteractiveViewer Sample";
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(
title: const Text(_title),
),
body: MystateLessWidget(),
),
);
}
}
class MystateLessWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(child: MyHome());
}
}
class MyHome extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyHomeState();
}
}
class MyHomeState extends State<MyHome> {
@override
Widget build(BuildContext context) {
return Center(
child: InteractiveViewer(
boundaryMargin: EdgeInsets.all(20.0),
minScale: 0.1,
maxScale: 1.6,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[Colors.orange, Colors.red],
stops: <double>[0.0, 1.0],
),
),
),
),
);
}
}
我的颤振版本是Flutter 1.17.5
飞镖版本是Dart 2.8.4
你能告诉我这里有什么问题吗?
【问题讨论】:
-
您需要将 Flutter 版本升级到最新版本,即
Flutter 1.20。在此处阅读有关发布更新的更多信息:medium.com/flutter/announcing-flutter-1-20-2aaf68c89c75
标签: flutter