Skip to content

Instantly share code, notes, and snippets.

@magnatronus
Created September 13, 2018 14:08
Show Gist options
  • Save magnatronus/acc51a60b5d707b44d6859022d6b7a14 to your computer and use it in GitHub Desktop.
Save magnatronus/acc51a60b5d707b44d6859022d6b7a14 to your computer and use it in GitHub Desktop.
Demo of Oscilloscope using Stream Data
/// Demo of using the oscilloscope package
/// This uses the output from the Acceleromter on a device
import 'package:flutter/material.dart';
import 'package:oscilloscope/oscilloscope.dart';
import 'package:sensors/sensors.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Oscilloscope Display Example",
home: Shell(),
);
}
}
class Shell extends StatefulWidget {
@override
_ShellState createState() => _ShellState();
}
class _ShellState extends State<Shell> {
List<double> traceX = List();
@override
initState() {
super.initState();
accelerometerEvents.listen( (AccelerometerEvent event){
setState(() {
traceX.add(event.x);
});
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
// Create A Scope Display
Oscilloscope scopeOne = Oscilloscope(
padding: 20.0,
backgroundColor: Colors.black,
traceColor: Colors.green,
yAxisMax: 10.0,
yAxisMin: -10.0,
dataSet: traceX,
);
// Generate the Scaffold
return Scaffold(
appBar: AppBar(
title: Text("OscilloScope Demo"),
),
body: Column(
children: <Widget>[
Expanded(flex: 1, child: scopeOne),
],
),
);
}
}
@kingcheng2000
Copy link

lib/main.dart:27:36: Error: Too few positional arguments: 2 required, 0 given.
List traceX = List.filled();
^
org-dartlang-sdk:///third_party/dart/sdk/lib/_internal/vm/lib/array_patch.dart:19:11: Context: Found this candidate, but the arguments don't match.
factory List.filled(int length, E fill, {bool growable: false}) {
^^^^^^

@magnatronus
Copy link
Author

Thats is because the gist is now 3 years old and the code is correct for the version of Dart/Flutter it was written again. The Dart language has advanced a great deal since then, null safety etc.

Looks like the list.filled() now needs params specified - see https://api.dart.dev/stable/2.13.4/dart-core/List/List.filled.html
Alternatively you could probably just init like this

List traceX = [];

@kingcheng2000
Copy link

Thats is because the gist is now 3 years old and the code is correct for the version of Dart/Flutter it was written again. The Dart language has advanced a great deal since then, null safety etc.

Looks like the list.filled() now needs params specified - see https://api.dart.dev/stable/2.13.4/dart-core/List/List.filled.html
Alternatively you could probably just init like this

List traceX = [];

The problem was solved! Thank you.

@tawat25
Copy link

tawat25 commented Dec 12, 2022

hi i have test code but i think slowl not real time . How to speed up to real time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment