当前位置:网站首页>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))),
);
}
}
边栏推荐
- MySQL installation steps - installing MySQL on Linux (3)
- Self discipline challenge 30 days
- Application and Optimization Practice of redis in vivo push platform
- 实时数据库 - 笔记
- Alibaba cloud server creates snapshots and rolls back disks
- 代码提交规范
- 扩展Prometheus的解决方案thanos的简介和几个月使用心得
- Techo day Tencent technology open day, June 28 online waiting for you!
- 服务器正文18:UDP可靠传输的理解和思考(读云凤博客有感)
- Ice - resources
猜你喜欢

数字藏品市场“三大套路”

Techo day Tencent technology open day, June 28 online waiting for you!

es6箭头函数中return的用法

How bacnet/ip gateway collects data of building centralized control system

Construction and exploration of vivo database and storage platform

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

扩展Prometheus的解决方案thanos的简介和几个月使用心得

Hack the box:routerspace

Kubernetes deploys a secret pit where thanos ruler sends repeated alarms

PLC -- Notes
随机推荐
LeetCode+ 66 - 70 高精度、二分专题
Is it safe to open a stock trading account on your mobile phone?
Is it safe for flush to open an account online
Leetcode+ 66 - 70 high precision, two sub topics
Is it safe to open an account on Dongfang fortune
Techo day Tencent technology open day, June 28 online waiting for you!
HTTP Caching Protocol practice
kubernetes删除pod的流程的源码简析
实时数据库 - 笔记
8 张图 | 剖析 Eureka 的首次同步注册表
R language ggmap visual cluster
R 语言 Hitters 数据分析
Mysql8.0 and mysql5.0 accessing JDBC connections
What is a consistent hash? What scenarios can it be applied to?
Leetcode+ 51 - 55 retrospective and dynamic planning topics
R 语言 ggmap 可视化集群
[thanos source code analysis series]thanos query component source code analysis
炒股开户在手机上安全吗?
Hack the box:routerspace
kubelet驱逐机制的源码分析