Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 { double xA, yA, zA, xG, yG, zG; //double x, y, z;

var _sensors = ['accelerometer', 'gyroscope']; String _selectedSensor; // _sensors[0];

@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: [ Padding( padding: const EdgeInsets.all(10.0), child: Text( "Select the sensor from the dropdown list", style: TextStyle(fontSize: 12.0, fontWeight: FontWeight.normal), ), ), DropdownButton( value: _selectedSensor, onChanged: (val) { setState(() { // updating the state _selectedSensor = val;

/*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( value: elem, child: Text(elem), ); }).toList(), ), Padding( padding: const EdgeInsets.all(10.0), ), Table( border: TableBorder.all( width: 2.0, color: Colors.blueAccent, style: BorderStyle.solid), children: [ TableRow( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text( "X axis: ", style: TextStyle(fontSize: 20.0), ), ), Padding( padding: const EdgeInsets.all(8.0), child: Text( xA.toStringAsFixed( 2), //trim the asis value to 2 digit after decimal point style: TextStyle(fontSize: 20.0)), ) ], ), TableRow( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text( "Y axis: ", style: TextStyle(fontSize: 20.0), ), ), Padding( padding: const EdgeInsets.all(8.0), child: Text( yA.toStringAsFixed( 2), //trim the asis value to 2 digit after decimal point style: TextStyle(fontSize: 20.0)), ) ], ), TableRow( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text( "Z axis: ", style: TextStyle(fontSize: 20.0), ), ), Padding( padding: const EdgeInsets.all(8.0), child: Text( zA.toStringAsFixed( 2), //trim the asis value to 2 digit after decimal point style: TextStyle(fontSize: 20.0)), ) ], ), ], ), ], ), )); } }

Assignment . Total points: 5 Create a simple app to read accelerometer and gyroscope events Create a drop down list with two options - 'accelerometer' and 'gyroscope Create a table with 3 rows - one each for X, Y and Z axes. Populate the table with current X, Y and Z values based on the selected sensor from drop down. . . Assignment . Total points: 5 Create a simple app to read accelerometer and gyroscope events Create a drop down list with two options - 'accelerometer' and 'gyroscope Create a table with 3 rows - one each for X, Y and Z axes. Populate the table with current X, Y and Z values based on the selected sensor from drop down

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

Define what is meant by communication.

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago