[英]InteractiveViewer class in flutter is not defined
我從這里閱讀有關 InteractiveViewer https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html
但是當我嘗試在我的代碼中使用 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
我的 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],
),
),
),
),
);
}
}
我的 flutter 版本是Flutter 1.17.5
和 dart 版本是Dart 2.8.4
你能告訴我這里有什么問題嗎?
問題是您使用的是舊版本的 flutter。
InteractiveViewer 發布於1.20 version of Flutter
因此,您需要升級您的 flutter,要升級您可以在命令提示符中使用以下命令:-
flutter upgrade
此命令獲取當前 Flutter 通道上可用的 Flutter SDK 的最新版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.