当前位置:网站首页>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();
}
},
),
),
);
}
}
边栏推荐
- No servers available for service: xxxx
- SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
- 5G电视难成竞争优势,视频资源成中国广电最后武器
- 深度学习 神经网络的优化方法
- Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
- Query optimizer for SQL optimization
- UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
- Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
- ES6 modularization
- 电商系统中红包活动设计
猜你喜欢
LVGL 8.2 Draw label with gradient color
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
现代控制理论入门+理解
LVGL 8.2 LED
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作
Docker compose public network deployment redis sentinel mode
关于FPGA底层资源的细节问题
程序员自曝接私活:10个月时间接了30多个单子,纯收入40万
Introduction to asynchronous task capability of function calculation - task trigger de duplication
随机推荐
Nowcoder rearrange linked list
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
A keepalived high availability accident made me learn it again
[algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
阿里被裁员工,找工作第N天,猎头又传来噩耗...
LVGL 8.2 List
产业互联网则具备更大的发展潜能,具备更多的行业场景
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
深度学习 网络正则化
How to build a technical team that will bring down the company?
Test evaluation of software testing
如何配和弦
[information retrieval] experiment of classification and clustering
深度学习7 Transformer系列实例分割Mask2Former
No servers available for service: xxxx
Ali was laid off employees, looking for a job n day, headhunters came bad news
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
C language programming
各大主流编程语言性能PK,结果出乎意料