报错如图

问题代码

import 'package:flutter/material.dart';void main() {runApp(SampleAppPage());
}class SampleAppPage extends StatefulWidget {const SampleAppPage({Key? key}) : super(key: key);@override_SampleAppPageState createState() => _SampleAppPageState();
}class _SampleAppPageState extends State<SampleAppPage>with SingleTickerProviderStateMixin {late AnimationController controller;late CurvedAnimation curve;@overridevoid initState() {super.initState();controller = AnimationController(duration: const Duration(milliseconds: 2000),vsync: this,);curve = CurvedAnimation(parent: controller,curve: Curves.easeIn,);}@overrideWidget build(BuildContext context) {return Scaffold(body: Center(child: GestureDetector(child: RotationTransition(turns: curve,child: const FlutterLogo(size: 200.0),),onDoubleTap: () {if (controller.isCompleted) {controller.reverse();} else {controller.forward();}},),),);}
}

原因: flutter 界面的根组件必须是MaterialApp

修复之后的代码

import 'package:flutter/material.dart';void main() {runApp(SampleApp());
}class SampleApp extends StatelessWidget {// This widget is the root of your application.const SampleApp({Key? key}) : super(key: key);@overrideWidget build(BuildContext context) {return const MaterialApp(title: 'Sample App',home: SampleAppPage(),);}
}class SampleAppPage extends StatefulWidget {const SampleAppPage({Key? key}) : super(key: key);@override_SampleAppPageState createState() => _SampleAppPageState();
}class _SampleAppPageState extends State<SampleAppPage>with SingleTickerProviderStateMixin {late AnimationController controller;late CurvedAnimation curve;@overridevoid initState() {super.initState();controller = AnimationController(duration: const Duration(milliseconds: 2000),vsync: this,);curve = CurvedAnimation(parent: controller,curve: Curves.easeIn,);}@overrideWidget build(BuildContext context) {return Scaffold(body: Center(child: GestureDetector(child: RotationTransition(turns: curve,child: const FlutterLogo(size: 200.0),),onDoubleTap: () {if (controller.isCompleted) {controller.reverse();} else {controller.forward();}},),),);}
}

flutter 报错 No MediaQuery widget ancestor found.相关推荐

  1. 【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )

    文章目录 一.报错信息 二.解决方案 一.报错信息 需要使用 MediaQuery 获取当前的 Padding ; import 'package:flutter/material.dart';/// ...

  2. 【错误记录】Flutter 界面报错 ( No MediaQuery widget ancestor found. | Scaffold widgets require a MediaQuery )

    文章目录 一.报错信息 二.解决方案 一.报错信息 Flutter 应用运行时报如下错误 : Launching lib\main.dart on Pixel 2 in debug mode... R ...

  3. flutter 报错之 No MediaQuery widget found.

    这里通过一个HelloWorld app来展示如何创建一个Widget并展示出来,并区分Material和非Material环境. hello_word.dart里的代码如下:  MaterialAp ...

  4. flutter报错Could not connect to lockdownd, error code -

    关于 flutter 报错信息解决方案 第一步: cmd+shift+g 前往 /var/db 文件夹,找到lockdown文件夹,修改读写权限 第二步 : 打开命令行,依次执行 brew updat ...

  5. flutter 报错java.net.URISyntaxException: Illegal character in opaque part at index 2

    记录flutter报错如下错误以及解决办法 FAILURE: Build failed with an exception. * What went wrong: Execution failed f ...

  6. Flutter报错BlocProvider.of() called with a context that does not contain a Bloc of type **.

    Flutter报错BlocProvider.of() called with a context that does not contain a Bloc of type **. 在使用flutter ...

  7. flutter:报错之: Looking up a deactivated widget's ancestor is unsafe

    错误内容 [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Looking up a deactivated widg ...

  8. 【错误记录】Flutter 组件报错 ( No Directionality widget found. | RichText widgets require a Directionality )

    文章目录 一.报错信息 二.解决方案 一.报错信息 报错信息 : Performing hot reload... Syncing files to device Pixel 2... Reloade ...

  9. 【错误记录】Flutter 报错 ( Android Studio 中 main.dart 左侧不显示设备栏 )

    文章目录 一.报错信息 二.解决方案 一 ( 备选方案 ) 三.解决方案 二 ( 推荐方案 ) 一.报错信息 为了解决 [错误记录]Flutter 构建报错 ( Because xxx require ...

  10. 【错误记录】Flutter 报错 ( Could not resolve io.flutter:flutter_embedding_debug:1.0.0. )

    文章目录 一. 报错信息 二. 解决方案 三. 备选方案 一. 报错信息 从网上下载了一个 Flutter 工程代码 , 打开时 , 报如下错误 ; Launching lib\main.dart o ...

最新文章

  1. c#中分割字符串的几种方法
  2. vue导航栏跳转路由
  3. MySQL批量更改数据库表结构字符集
  4. 地面指示标志_详解消防应急照明和疏散指示系统的施工及安装方法消防施工
  5. python矩阵函数_NumPy 矩阵库函数
  6. QuillBot:又一个值得拥有的论文润色工具
  7. mysql查看binlog_MySQL的binlog数据如何查看
  8. pycharm自定义代码段
  9. sensor曝光量和曝光行的区别_求教:关于lcd和sensor的几个问题和讨论
  10. ADO.NET基础复习(二)
  11. SSM房屋租赁管理系统
  12. Linux编译并更新内核(替换Linux内核)
  13. 年轻人最好要接触」的东西
  14. python100天发音_GitHub - hhttss999/Python-100-Days: Python - 100天从新手到大师
  15. 联想LENOVO K2450升级(或全新安装)Windows 10后不能正常关机的解决方案
  16. libnet发包java语言_Net-speeder多倍发包脚本
  17. both and和both of 得用法 和区别
  18. 小鹤双拼提速方法个人经验-by老随风
  19. vue移动端图片上传
  20. 如何查看电脑是否支持Wi-Fi 6

热门文章

  1. myeclipse配置下面没有Tomcat的解决办法
  2. java实现支付宝网页扫码支付
  3. matlab绘制函数傅里叶,MATLAB中如何实现矩形函数的傅里叶变换
  4. qq微信电脑客户端 for mac v1.0.0.6 官方版
  5. 怎样可以促进睡眠质量?睡眠不好一定要知道这些方法
  6. hypermedia_Hypermedia REST API简介
  7. Python几个编程小作业
  8. iexplore.exe_如何一次杀死所有iexplore.exe进程?
  9. PD快充3.0协议芯片
  10. 亲身经历,大龄程序员,为什么难找对象!