当前位置:网站首页>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))),
);
}
}
边栏推荐
- Makefile
- Design and practice of vivo sensitive word matching system
- SQL statement optimization steps (1)
- [thanos source code analysis series]thanos query component source code analysis
- [c #] [reprint]furion frame address and tutorial address
- XML serialization backward compatible
- goland IDE和delve调试位于kubernetes集群中的go程序
- Modifying MySQL user name root under Linux
- My MVVM open source project "travel epidemic prevention app" has been released
- Comment la passerelle BACnet / IP recueille - t - elle les données du système central de contrôle des bâtiments?
猜你喜欢

GoLand IDE and delve debug Go programs in kubernetes cluster

SQL statement optimization steps (1)

PLC -- 笔记

MySQL installation steps - how to create a virtual machine under Linux (1)

Open62541 import nodeset file directly

The practice of event driven architecture in vivo content platform

Construction and exploration of vivo database and storage platform

MySQL installation steps - Linux configuration file JDK installation (II)

From the beginning of redis learning to take-off, this article is all for you

数字藏品市场“三大套路”
随机推荐
Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
R 语言绘制 动画气泡图
以动态规划的方式求解最长回文子串
东方财富上开户是安全的吗
Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known
A gadget can write crawlers faster
Comprehensive analysis of real enterprise software testing process
[thanos source code analysis series]thanos query component source code analysis
ice - 资源
卸载重装最新版mysql数据库亲测有效
GoLand IDE and delve debug Go programs in kubernetes cluster
Understanding of OPC protocol
扩展Prometheus的解决方案thanos的简介和几个月使用心得
Block transmission by golang gin framework
Huawei cloud computing physical node cna installation tutorial
腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Optimization steps of SQL statements (II) -- MySQL statement optimization
Alibaba cloud server creates snapshots and rolls back disks
Code submission specification