1919// See window_size_channel.dart for documentation.
2020const char kChannelName [] = " flutter/windowsize" ;
2121const char kBadArgumentsError [] = " Bad Arguments" ;
22+ const char kNoScrenError [] = " No Screen" ;
2223const char kGetScreenListMethod [] = " getScreenList" ;
2324const char kGetWindowInfoMethod [] = " getWindowInfo" ;
2425const char kSetWindowFrameMethod [] = " setWindowFrame" ;
@@ -49,12 +50,16 @@ G_DEFINE_TYPE(FlWindowSizePlugin, fl_window_size_plugin, g_object_get_type())
4950// Gets the window being controlled.
5051GtkWindow* get_window(FlWindowSizePlugin* self) {
5152 FlView* view = fl_plugin_registrar_get_view (self->registrar );
53+ if (view == nullptr ) return nullptr ;
54+
5255 return GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
5356}
5457
5558// Gets the display connection.
5659GdkDisplay* get_display (FlWindowSizePlugin* self) {
5760 FlView* view = fl_plugin_registrar_get_view (self->registrar );
61+ if (view == nullptr ) return nullptr ;
62+
5863 return gtk_widget_get_display (GTK_WIDGET (view));
5964}
6065
@@ -97,6 +102,11 @@ static FlMethodResponse* get_screen_list(FlWindowSizePlugin* self) {
97102 g_autoptr (FlValue) screens = fl_value_new_list ();
98103
99104 GdkDisplay* display = get_display (self);
105+ if (display == nullptr ) {
106+ return FL_METHOD_RESPONSE (
107+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
108+ }
109+
100110 gint n_monitors = gdk_display_get_n_monitors (display);
101111 for (gint i = 0 ; i < n_monitors; i++) {
102112 GdkMonitor* monitor = gdk_display_get_monitor (display, i);
@@ -109,6 +119,10 @@ static FlMethodResponse* get_screen_list(FlWindowSizePlugin* self) {
109119// Gets information about the Flutter window.
110120static FlMethodResponse* get_window_info (FlWindowSizePlugin* self) {
111121 GtkWindow* window = get_window (self);
122+ if (window == nullptr ) {
123+ return FL_METHOD_RESPONSE (
124+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
125+ }
112126
113127 g_autoptr (FlValue) window_info = fl_value_new_map ();
114128
@@ -158,6 +172,11 @@ static FlMethodResponse* set_window_frame(FlWindowSizePlugin* self,
158172 double height = fl_value_get_float (fl_value_get_list_value (args, 3 ));
159173
160174 GtkWindow* window = get_window (self);
175+ if (window == nullptr ) {
176+ return FL_METHOD_RESPONSE (
177+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
178+ }
179+
161180 gtk_window_move (window, static_cast <gint>(x), static_cast <gint>(y));
162181 gtk_window_resize (window, static_cast <gint>(width),
163182 static_cast <gint>(height));
@@ -183,6 +202,11 @@ static FlMethodResponse* set_window_minimum_size(FlWindowSizePlugin* self,
183202 double width = fl_value_get_float (fl_value_get_list_value (args, 0 ));
184203 double height = fl_value_get_float (fl_value_get_list_value (args, 1 ));
185204
205+ if (get_window () == nullptr ) {
206+ return FL_METHOD_RESPONSE (
207+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
208+ }
209+
186210 if (width >= 0 && height >= 0 ) {
187211 self->window_geometry .min_width = static_cast <gint>(width);
188212 self->window_geometry .min_height = static_cast <gint>(height);
@@ -204,6 +228,11 @@ static FlMethodResponse* set_window_maximum_size(FlWindowSizePlugin* self,
204228 double width = fl_value_get_float (fl_value_get_list_value (args, 0 ));
205229 double height = fl_value_get_float (fl_value_get_list_value (args, 1 ));
206230
231+ if (get_window () == nullptr ) {
232+ return FL_METHOD_RESPONSE (
233+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
234+ }
235+
207236 self->window_geometry .max_width = static_cast <gint>(width);
208237 self->window_geometry .max_height = static_cast <gint>(height);
209238
@@ -221,6 +250,10 @@ static FlMethodResponse* set_window_title(FlWindowSizePlugin* self,
221250 }
222251
223252 GtkWindow* window = get_window (self);
253+ if (window == nullptr ) {
254+ return FL_METHOD_RESPONSE (
255+ fl_method_error_response_new (kNoScreenError , nullptr , nullptr ));
256+ }
224257 gtk_window_set_title (window, fl_value_get_string (args));
225258
226259 return FL_METHOD_RESPONSE (fl_method_success_response_new (nullptr ));
0 commit comments