@@ -67,11 +67,6 @@ class PassiveWebViewWidget extends StatefulWidget {
6767 final List <VariableData > variables;
6868 final WidgetBuildSettings settings;
6969
70- static const Set <TargetPlatform > supportedPlatforms = {
71- TargetPlatform .android,
72- TargetPlatform .iOS,
73- };
74-
7570 const PassiveWebViewWidget ({
7671 super .key,
7772 required this .node,
@@ -84,6 +79,81 @@ class PassiveWebViewWidget extends StatefulWidget {
8479}
8580
8681class _PassiveWebViewWidgetState extends State <PassiveWebViewWidget > {
82+ @override
83+ Widget build (BuildContext context) {
84+ return AdaptiveNodeBox (
85+ node: widget.node,
86+ child: RawWebViewWidget (
87+ properties: widget.node.properties,
88+ settings: widget.settings,
89+ ),
90+ );
91+ }
92+ }
93+
94+ class WebViewPreviewWidget extends StatelessWidget {
95+ final Widget icon;
96+ final double aspectRatio;
97+
98+ const WebViewPreviewWidget ({
99+ super .key,
100+ required this .icon,
101+ this .aspectRatio = 1 ,
102+ });
103+
104+ @override
105+ Widget build (BuildContext context) {
106+ return Container (
107+ clipBehavior: Clip .antiAlias,
108+ decoration: BoxDecoration (
109+ borderRadius: BorderRadius .circular (8 ),
110+ border: Border .all (color: Colors .blue),
111+ ),
112+ child: Container (
113+ margin: const EdgeInsets .all (8 ),
114+ alignment: Alignment .center,
115+ decoration: BoxDecoration (
116+ color: Colors .blue.shade50,
117+ borderRadius: BorderRadius .circular (6 ),
118+ ),
119+ child: FractionallySizedBox (
120+ widthFactor: aspectRatio > 1 ? 0.2 : null ,
121+ heightFactor: aspectRatio < 1 ? 0.2 : null ,
122+ child: LayoutBuilder (builder: (context, constraints) {
123+ return IconTheme (
124+ data: IconThemeData (
125+ color: Colors .blue,
126+ size: min (constraints.maxWidth, constraints.maxHeight),
127+ ),
128+ child: icon,
129+ );
130+ }),
131+ ),
132+ ),
133+ );
134+ }
135+ }
136+
137+ class RawWebViewWidget extends StatefulWidget {
138+ final WebViewProperties properties;
139+ final WidgetBuildSettings settings;
140+
141+ static const Set <TargetPlatform > supportedPlatforms = {
142+ TargetPlatform .android,
143+ TargetPlatform .iOS,
144+ };
145+
146+ const RawWebViewWidget ({
147+ super .key,
148+ required this .properties,
149+ required this .settings,
150+ });
151+
152+ @override
153+ State <RawWebViewWidget > createState () => _RawWebViewWidgetState ();
154+ }
155+
156+ class _RawWebViewWidgetState extends State <RawWebViewWidget > {
87157 late WebViewController _controller;
88158
89159 bool _isDataLoaded = false ;
@@ -96,7 +166,7 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
96166 return ;
97167 }
98168
99- final props = widget.node. properties;
169+ final props = widget.properties;
100170 if (kIsWeb) {
101171 // WebView on web only supports loadRequest. Any other method invocation
102172 // on the controller will result in an exception. Be aware!!
@@ -143,7 +213,7 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
143213
144214 void _loadData () {
145215 final ScopedValues scopedValues = ScopedValues .of (context);
146- final props = widget.node. properties;
216+ final props = widget.properties;
147217 switch (props.webviewType) {
148218 case WebViewType .webpage:
149219 final properties = props as WebPageWebViewProperties ;
@@ -189,27 +259,26 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
189259
190260 @override
191261 Widget build (BuildContext context) {
192- final props = widget.node. properties;
193- Widget wid ;
262+ final props = widget.properties;
263+ Widget child ;
194264 switch (props.webviewType) {
195265 case WebViewType .webpage:
196- wid = buildWebpageWebView (context, props as WebPageWebViewProperties );
266+ child = buildWebpageWebView (context, props as WebPageWebViewProperties );
197267 case WebViewType .googleMaps:
198- wid = buildGoogleMapsWebView (
268+ child = buildGoogleMapsWebView (
199269 context, props as GoogleMapsWebViewProperties );
200270 case WebViewType .twitter:
201- wid = buildTwitterWebView (context, props as TwitterWebViewProperties );
271+ child = buildTwitterWebView (context, props as TwitterWebViewProperties );
202272 }
203273
204- return AdaptiveNodeBox (node : widget.node, child: wid) ;
274+ return child;
205275 }
206276
207277 Widget buildWebpageWebView (
208278 BuildContext context, WebPageWebViewProperties properties) {
209279 if (! isPlatformSupportedForWebView || widget.settings.isPreview) {
210- return WebViewPreviewWidget (
211- icon: const Icon (Icons .language_rounded),
212- node: widget.node,
280+ return const WebViewPreviewWidget (
281+ icon: Icon (Icons .language_rounded),
213282 );
214283 }
215284
@@ -239,9 +308,8 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
239308 Widget buildGoogleMapsWebView (
240309 BuildContext context, GoogleMapsWebViewProperties properties) {
241310 if (! isPlatformSupportedForWebView || widget.settings.isPreview) {
242- return WebViewPreviewWidget (
243- icon: const Icon (Icons .map_outlined),
244- node: widget.node,
311+ return const WebViewPreviewWidget (
312+ icon: Icon (Icons .map_outlined),
245313 );
246314 }
247315
@@ -262,10 +330,9 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
262330 Widget buildTwitterWebView (
263331 BuildContext context, TwitterWebViewProperties properties) {
264332 if (! isPlatformSupportedForWebView || widget.settings.isPreview) {
265- return WebViewPreviewWidget (
266- icon: const ImageIcon (
333+ return const WebViewPreviewWidget (
334+ icon: ImageIcon (
267335 NetworkImage ('https://img.icons8.com/color/344/twitter--v2.png' )),
268- node: widget.node,
269336 );
270337 }
271338
@@ -297,49 +364,3 @@ class _PassiveWebViewWidgetState extends State<PassiveWebViewWidget> {
297364 );
298365 }
299366}
300-
301- class WebViewPreviewWidget extends StatelessWidget {
302- final Widget icon;
303- final BaseNode node;
304-
305- const WebViewPreviewWidget ({
306- super .key,
307- required this .icon,
308- required this .node,
309- });
310-
311- @override
312- Widget build (BuildContext context) {
313- return AdaptiveNodeBox (
314- node: node,
315- child: Container (
316- clipBehavior: Clip .antiAlias,
317- decoration: BoxDecoration (
318- borderRadius: BorderRadius .circular (8 ),
319- border: Border .all (color: Colors .blue),
320- ),
321- child: Container (
322- margin: const EdgeInsets .all (8 ),
323- alignment: Alignment .center,
324- decoration: BoxDecoration (
325- color: Colors .blue.shade50,
326- borderRadius: BorderRadius .circular (6 ),
327- ),
328- child: FractionallySizedBox (
329- widthFactor: node.basicBoxLocal.aspectRatio > 1 ? 0.2 : null ,
330- heightFactor: node.basicBoxLocal.aspectRatio < 1 ? 0.2 : null ,
331- child: LayoutBuilder (builder: (context, constraints) {
332- return IconTheme (
333- data: IconThemeData (
334- color: Colors .blue,
335- size: min (constraints.maxWidth, constraints.maxHeight),
336- ),
337- child: icon,
338- );
339- }),
340- ),
341- ),
342- ),
343- );
344- }
345- }
0 commit comments