[英]InteractiveViewer class in flutter is not defined
I was reading about InteractiveViewer from here https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html我从这里阅读有关 InteractiveViewer https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html
But when I tried to use InteractiveViewer in my code It gave me an error:-但是当我尝试在我的代码中使用 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
My flutter code is below:-我的 flutter 代码如下:-
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],
),
),
),
),
);
}
}
My flutter version is Flutter 1.17.5
and dart version is Dart 2.8.4
我的 flutter 版本是
Flutter 1.17.5
和 dart 版本是Dart 2.8.4
Can you please tell me what is the problem here.你能告诉我这里有什么问题吗?
The problem is that you are using an old version of flutter.问题是您使用的是旧版本的 flutter。
InteractiveViewer was released in 1.20 version of Flutter
InteractiveViewer 发布于
1.20 version of Flutter
So you need to upgrade your flutter, To upgrade you can use the following command in the command-prompt:-因此,您需要升级您的 flutter,要升级您可以在命令提示符中使用以下命令:-
flutter upgrade
This command gets the most recent version of the Flutter SDK that's available on your current Flutter channel.此命令获取当前 Flutter 通道上可用的 Flutter SDK 的最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.