Question
import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sensors/sensors.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { // This widget is the root of your
import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sensors/sensors.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } }
class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); }
class _MyHomePageState extends State
var _sensors =
@override void initState() { // TODO: implement initState super.initState(); accelerometerEvents.listen((AccelerometerEvent eventA) { setState(() { xA = eventA.x; yA = eventA.y; zA = eventA.z; //x = xA; //y = yA; //z = zA; }); }); //get the sensor data and set then to the data types
gyroscopeEvents.listen((GyroscopeEvent eventG) { setState(() { xG = eventG.x; yG = eventG.y; zG = eventG.z; }); }); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Flutter Sensor Library"), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children:
/*if (_selectedSensor == 'accelerometer') { // do something here x = xA; y = yA; z = zA; }
if (_selectedSensor == 'gyroscope') { // do something here x = xG; y = yG; z = zG; }*/ }); }, items: _sensors.map((String elem) { return DropdownMenuItem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started