Fix crash in Linux platform channel example. (#155735)
When running this example it was crashing, so investigated a fixed a couple of bugs.
This commit is contained in:
parent
bff135153d
commit
cf4dace52b
@ -42,8 +42,7 @@ static void update_charging_state(MyApplication* self) {
|
|||||||
|
|
||||||
const gchar* charge_event = "discharging";
|
const gchar* charge_event = "discharging";
|
||||||
for (guint i = 0; i < self->battery_devices->len; i++) {
|
for (guint i = 0; i < self->battery_devices->len; i++) {
|
||||||
UpDevice* device =
|
UpDevice* device = UP_DEVICE(g_ptr_array_index(self->battery_devices, i));
|
||||||
static_cast<UpDevice*>(g_ptr_array_index(self->battery_devices, i));
|
|
||||||
|
|
||||||
guint state;
|
guint state;
|
||||||
g_object_get(device, "state", &state, nullptr);
|
g_object_get(device, "state", &state, nullptr);
|
||||||
@ -97,8 +96,7 @@ static void up_device_removed_cb(MyApplication* self, UpDevice* device) {
|
|||||||
static FlMethodResponse* get_battery_level(MyApplication* self) {
|
static FlMethodResponse* get_battery_level(MyApplication* self) {
|
||||||
// Find the first available battery and use that.
|
// Find the first available battery and use that.
|
||||||
for (guint i = 0; i < self->battery_devices->len; i++) {
|
for (guint i = 0; i < self->battery_devices->len; i++) {
|
||||||
UpDevice* device =
|
UpDevice* device = UP_DEVICE(g_ptr_array_index(self->battery_devices, i));
|
||||||
static_cast<UpDevice*>(g_ptr_array_index(self->battery_devices, i));
|
|
||||||
|
|
||||||
double percentage;
|
double percentage;
|
||||||
g_object_get(device, "percentage", &percentage, nullptr);
|
g_object_get(device, "percentage", &percentage, nullptr);
|
||||||
@ -225,8 +223,7 @@ static void my_application_activate(GApplication* application) {
|
|||||||
g_autoptr(GPtrArray) devices = up_client_get_devices(self->up_client);
|
g_autoptr(GPtrArray) devices = up_client_get_devices(self->up_client);
|
||||||
#endif
|
#endif
|
||||||
for (guint i = 0; i < devices->len; i++) {
|
for (guint i = 0; i < devices->len; i++) {
|
||||||
g_autoptr(UpDevice) device =
|
UpDevice* device = UP_DEVICE(g_ptr_array_index(devices, i));
|
||||||
static_cast<UpDevice*>(g_ptr_array_index(devices, i));
|
|
||||||
up_device_added_cb(self, device);
|
up_device_added_cb(self, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,8 +265,7 @@ static void my_application_dispose(GObject* object) {
|
|||||||
MyApplication* self = MY_APPLICATION(object);
|
MyApplication* self = MY_APPLICATION(object);
|
||||||
|
|
||||||
for (guint i = 0; i < self->battery_devices->len; i++) {
|
for (guint i = 0; i < self->battery_devices->len; i++) {
|
||||||
UpDevice* device =
|
UpDevice* device = UP_DEVICE(g_ptr_array_index(self->battery_devices, i));
|
||||||
static_cast<UpDevice*>(g_ptr_array_index(self->battery_devices, i));
|
|
||||||
g_signal_handlers_disconnect_matched(device, G_SIGNAL_MATCH_DATA, 0, 0,
|
g_signal_handlers_disconnect_matched(device, G_SIGNAL_MATCH_DATA, 0, 0,
|
||||||
nullptr, nullptr, self);
|
nullptr, nullptr, self);
|
||||||
}
|
}
|
||||||
@ -278,7 +274,7 @@ static void my_application_dispose(GObject* object) {
|
|||||||
|
|
||||||
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
|
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
|
||||||
g_clear_object(&self->up_client);
|
g_clear_object(&self->up_client);
|
||||||
g_clear_object(&self->battery_devices);
|
g_clear_pointer(&self->battery_devices, g_ptr_array_unref);
|
||||||
g_clear_object(&self->battery_channel);
|
g_clear_object(&self->battery_channel);
|
||||||
g_clear_object(&self->charging_channel);
|
g_clear_object(&self->charging_channel);
|
||||||
g_clear_pointer(&self->last_charge_event, g_free);
|
g_clear_pointer(&self->last_charge_event, g_free);
|
||||||
|
15
examples/platform_channel/test/platform_channel_test.dart
Normal file
15
examples/platform_channel/test/platform_channel_test.dart
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:platform_channel/main.dart' as platform_channel;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Platform channel smoke test', (WidgetTester tester) async {
|
||||||
|
platform_channel.main(); // builds the app and schedules a frame but doesn't trigger one
|
||||||
|
await tester.pump(); // triggers a frame
|
||||||
|
|
||||||
|
expect(find.textContaining('Battery level: '), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user