当前位置:网站首页>Flutter realizes the function of "shake"
Flutter realizes the function of "shake"
2022-06-28 07:25:00 【Dense information】
Reference resources
Reference resources
sensors_plus: ^1.3.2
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:sensors_plus/sensors_plus.dart';
import 'package:social_im/common/colors.dart';
// Shake a shake games
class ShakeGame extends StatefulWidget {
const ShakeGame({
Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => ShakeGameState();
}
class ShakeGameState extends State<ShakeGame> {
// Whether the pop-up window has been displayed
bool isShow = false;
final _streamSubscriptions = <StreamSubscription<dynamic>>[];
@override
void initState() {
// Monitor the shaking of the mobile phone
shakeListen();
super.initState();
}
@override
void dispose() {
super.dispose();
// Cancel monitoring
for (final subscription in _streamSubscriptions) {
subscription.cancel();
}
}
shakeListen() {
_streamSubscriptions
.add(userAccelerometerEvents.listen((UserAccelerometerEvent event) {
// Not affected by gravity
print("event Value ${event}");
int value = 4;
if (event.x >= value ||
event.x <= -value ||
event.y >= value ||
event.y <= -value ||
event.z >= value ||
event.z <= -value) {
print(" Already shaken ");
if (isShow == false) {
setState(() {
isShow = true;
});
// Delay two seconds to match the user
Future.delayed(const Duration(seconds: 2), () {
print(" Pop up window ");
});
}
}
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text(' shake '),
backgroundColor: CommonColors.getThemeColor(),
),
body: Center(
child: Padding(
padding: const EdgeInsets.only(left: 5),
child: Image(
image: isShow
? const AssetImage('assets/images/icon_lan_match.png')
: const AssetImage(
'assets/images/conversion/icon_conversion_album.png'),
width: 6,
height: 11))),
);
}
}
边栏推荐
- Force buckle 515 Find the maximum value in each tree row
- 自律挑战30天
- Hack the box:routerspace
- Devtools implementation principle and performance analysis practice
- 华为云计算之物理节点CNA安装教程
- 力扣515.在每棵树行中找最大值
- Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
- MySQL installation steps - how to create a virtual machine under Linux (1)
- Encyclopedia of scala operators
- Libuv framework echo server C source code explanation (TCP part)
猜你喜欢

In idea, the get and set methods may be popular because the Lombok plug-in is not installed

小小一款代码编辑器竟然也可以有程序运行之功能——Sublime Text3运行各种语言程序的总结

什么是EC鼓风机(ec blower fan)?

MySQL installation steps - Linux configuration file JDK installation (II)
面经---测试工程师web端自动化---大厂面试题

kubernetes删除pod的流程的源码简析

linux下修改mysql用户名root

A small code editor can also run programs -- a summary of sublime Text3 running programs in various languages

网传互联网公司加班表,排名第一的没悬念

The practice of event driven architecture in vivo content platform
随机推荐
Makefile
XML serialization backward compatible
NDK 交叉编译
This keyword details
Will Internet talents be scarce in the future? Which technology directions are popular?
什么是一致性哈希?可以应用在哪些场景?
R 和 rgl 绘制 3D 结
R language ggmap visual cluster
Block transmission by golang gin framework
代码提交规范
Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio
卸载重装最新版mysql数据库亲测有效
SQL statement optimization steps (1)
Optimization steps of SQL statements (II) -- MySQL statement optimization
面经---测试工程师web端自动化---大厂面试题
自动化测试的生命周期是什么?
Is it safe to open an account on Dongfang fortune
7-1 懂的都懂
An important term in MySQL -- CRUD
Spark 离线开发框架设计与实现