mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Update pedometer sample for jni 0.8.0 (#2237)
Also clean up some nearby Dart code :)
This commit is contained in:
@@ -188,28 +188,21 @@ class _HomeState extends State<Home> {
|
||||
}
|
||||
}
|
||||
|
||||
// Axis labels for bottom of chart
|
||||
// Axis labels for bottom of chart.
|
||||
Widget getBottomTitles(double value, TitleMeta meta) {
|
||||
String text;
|
||||
switch (value.toInt()) {
|
||||
case 0:
|
||||
text = '12AM';
|
||||
break;
|
||||
case 6:
|
||||
text = '6AM';
|
||||
break;
|
||||
case 12:
|
||||
text = '12PM';
|
||||
break;
|
||||
case 18:
|
||||
text = '6PM';
|
||||
break;
|
||||
default:
|
||||
text = '';
|
||||
}
|
||||
final timeText = switch (value.toInt()) {
|
||||
0 => '12AM',
|
||||
6 => '6AM',
|
||||
12 => '12PM',
|
||||
18 => '6PM',
|
||||
_ => ''
|
||||
};
|
||||
return SideTitleWidget(
|
||||
axisSide: meta.axisSide,
|
||||
space: 4,
|
||||
child: Text(text, style: TextStyle(fontSize: 14, color: Colors.blue[900])),
|
||||
child: Text(
|
||||
timeText,
|
||||
style: TextStyle(fontSize: 14, color: Colors.blue[900]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ import 'package:pedometer/health_connect.dart' as hc;
|
||||
|
||||
/// Class to hold the information needed for the chart
|
||||
class Steps {
|
||||
String startHour;
|
||||
int steps;
|
||||
final String startHour;
|
||||
final int steps;
|
||||
|
||||
Steps(this.startHour, this.steps);
|
||||
}
|
||||
|
||||
@@ -30,9 +31,9 @@ class _IOSStepsRepo implements StepsRepo {
|
||||
static const _dylibPath =
|
||||
'/System/Library/Frameworks/CoreMotion.framework/CoreMotion';
|
||||
|
||||
// Bindings for the CMPedometer class
|
||||
// Bindings for the CMPedometer class.
|
||||
final lib = pd.PedometerBindings(ffi.DynamicLibrary.open(_dylibPath));
|
||||
// Bindings for the helper function
|
||||
// Bindings for the helper function.
|
||||
final helpLib = pd.PedometerBindings(ffi.DynamicLibrary.process());
|
||||
|
||||
late final pd.CMPedometer client;
|
||||
@@ -68,7 +69,8 @@ class _IOSStepsRepo implements StepsRepo {
|
||||
pd.NSDate dateConverter(DateTime dartDate) {
|
||||
// Format dart date to string.
|
||||
final formattedDate = DateFormat(StepsRepo._formatString).format(dartDate);
|
||||
// Get current timezone. If eastern african change to AST to follow with NSDate.
|
||||
// Get current timezone.
|
||||
// If eastern african change to AST to follow with NSDate.
|
||||
final tz = dartDate.timeZoneName == "EAT" ? "AST" : dartDate.timeZoneName;
|
||||
|
||||
// Create a new NSString with the formatted date and timezone.
|
||||
@@ -112,7 +114,7 @@ class _IOSStepsRepo implements StepsRepo {
|
||||
start, end, handler);
|
||||
}
|
||||
|
||||
return (await Future.wait(futures)).nonNulls.toList();
|
||||
return (await futures.wait).nonNulls.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +124,9 @@ class _AndroidStepsRepo implements StepsRepo {
|
||||
late final hc.HealthConnectClient client;
|
||||
|
||||
_AndroidStepsRepo() {
|
||||
jni.Jni.initDLApi();
|
||||
activity = hc.Activity.fromRef(jni.Jni.getCurrentActivity());
|
||||
activity = hc.Activity.fromReference(jni.Jni.getCurrentActivity());
|
||||
applicationContext =
|
||||
hc.Context.fromRef(jni.Jni.getCachedApplicationContext());
|
||||
hc.Context.fromReference(jni.Jni.getCachedApplicationContext());
|
||||
client = hc.HealthConnectClient.getOrCreate1(applicationContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,12 +39,9 @@ dependencies:
|
||||
# the parent directory to use the current plugin's version.
|
||||
path: ../
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
ffi: ^2.1.0
|
||||
ffi: ^2.1.2
|
||||
intl: ^0.19.0
|
||||
jni: ^0.7.0
|
||||
jni: ^0.8.0
|
||||
fl_chart: ^0.67.0
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user