当前位置:网站首页>Flutter reports an error no mediaquery widget ancestor found
Flutter reports an error no mediaquery widget ancestor found
2022-07-04 14:54:00 【Liu Xiaobo】
Error report as shown in the figure
Problem code
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;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000),
vsync: this,
);
curve = CurvedAnimation(
parent: controller,
curve: Curves.easeIn,
);
}
@override
Widget 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();
}
},
),
),
);
}
}
reason : flutter The root component of the interface must be MaterialApp
The repaired code
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);
@override
Widget 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;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000),
vsync: this,
);
curve = CurvedAnimation(
parent: controller,
curve: Curves.easeIn,
);
}
@override
Widget 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();
}
},
),
),
);
}
}
边栏推荐
- Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
- openresty 限流
- PLC Analog input analog conversion FC s_ ITR (CoDeSys platform)
- 關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
- Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
- Digi restarts XBee Pro S2C production. Some differences need to be noted
- 信号处理之一阶RC低通滤波器宏指令实现(繁易触摸屏)
- Leecode learning notes - Joseph problem
- 深度学习 神经网络案例(手写数字识别)
- Leetcode t49: grouping of alphabetic words
猜你喜欢
Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
No servers available for service: xxxx
现代控制理论入门+理解
Expose Ali's salary and position level
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路
《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
随机推荐
LVGL 8.2 Line wrap, recoloring and scrolling
LVGL 8.2 keyboard
Introduction to modern control theory + understanding
LVGL 8.2 LED
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
阿里被裁员工,找工作第N天,猎头又传来噩耗...
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
What are the concepts of union, intersection, difference and complement?
LVGL 8.2 keyboard
为什么国产手机用户换下一部手机时,都选择了iPhone?
LVGL 8.2 Line
Transplant tinyplay for imx6q development board QT system
LVGL 8.2 Sorting a List using up and down buttons
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
局部修改-渐进型开发
自动控制原理快速入门+理解
深度学习 网络正则化
LVGL 8.2 Line wrap, recoloring and scrolling
C language book rental management system
UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...