Skip to content

Commit a9f8420

Browse files
committed
Simulator #11
1 parent c774b31 commit a9f8420

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

lib/src/auth/codelessly_auth_manager.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class CodelesslyAuthManager extends AuthManager {
150150
// however, we also authenticate in the background to ensure the token
151151
// is still valid. We do this so as to not block the UI, we load whatever
152152
// is there immediately while we run our security in the background.
153+
154+
if (_disposed) return;
155+
153156
if (!isAuthenticated()) {
154157
log('Token is not authenticated. Authenticating...');
155158
await authenticate();

lib/src/transformers/node_transformers/passive_canvas_transformer.dart

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:codelessly_api/codelessly_api.dart';
44
import 'package:flutter/material.dart';
5+
import 'package:flutter/scheduler.dart';
56
import 'package:flutter/services.dart';
67
import 'package:provider/provider.dart';
78

@@ -397,24 +398,28 @@ class _PassiveCanvasWidgetState extends State<PassiveCanvasWidget> {
397398
void initState() {
398399
super.initState();
399400

400-
codelessly = context.read<Codelessly>();
401-
final String? myLayoutId = codelessly!
402-
.dataManager.publishModel?.layouts.dataMap.entries
403-
.firstWhere((entry) {
404-
return entry.value.canvasIds.contains(widget.node.id);
405-
}).key;
406-
407-
// Set the system UI brightness to the canvas brightness.
408-
codelessly!.setSystemUIBrightness(widget.node.properties.brightness);
409-
410-
// Listen for navigation events to update the system UI brightness back
411-
// again, such as if this canvas was navigated away from, but then the view
412-
// pops and goes back to this canvas.
413-
codelessly!.addNavigationListener('canvas-${widget.node.id}',
414-
(event, layoutId) {
415-
if (myLayoutId == layoutId) {
416-
codelessly!.setSystemUIBrightness(widget.node.properties.brightness);
417-
}
401+
SchedulerBinding.instance.addPostFrameCallback((_) {
402+
if (!mounted) return;
403+
404+
codelessly = context.read<Codelessly>();
405+
final String? myLayoutId = codelessly!
406+
.dataManager.publishModel?.layouts.dataMap.entries
407+
.firstWhere((entry) {
408+
return entry.value.canvasIds.contains(widget.node.id);
409+
}).key;
410+
411+
// Set the system UI brightness to the canvas brightness.
412+
codelessly!.setSystemUIBrightness(widget.node.properties.brightness);
413+
414+
// Listen for navigation events to update the system UI brightness back
415+
// again, such as if this canvas was navigated away from, but then the view
416+
// pops and goes back to this canvas.
417+
codelessly!.addNavigationListener('canvas-${widget.node.id}',
418+
(event, layoutId) {
419+
if (myLayoutId == layoutId) {
420+
codelessly!.setSystemUIBrightness(widget.node.properties.brightness);
421+
}
422+
});
418423
});
419424
}
420425

lib/src/transformers/node_transformers/passive_web_view_transformer_mobile.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ class _RawWebViewWidgetState extends State<RawWebViewWidget> {
193193
WebViewMediaAutoPlaybackPolicy.alwaysPlayAllMedia);
194194
}
195195

196-
_controller.setBackgroundColor(
197-
props.backgroundColor?.toFlutterColor() ?? Colors.transparent);
196+
if (defaultTargetPlatform != TargetPlatform.macOS) {
197+
_controller.setBackgroundColor(
198+
props.backgroundColor?.toFlutterColor() ?? Colors.transparent);
199+
}
198200
}
199201

200202
@override

0 commit comments

Comments
 (0)