Skip to content

Commit ec1342f

Browse files
committed
Miscellaneous fixes
- Fix sdk disposing not working properly. - Fix embedded canvases crashing with local storage. - Fix and improve CStatus constructors.
1 parent bd91bf0 commit ec1342f

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

lib/src/codelessly.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class Codelessly {
171171
/// if [completeDispose] is true, the SDK's internal stream controllers are
172172
/// also disposed instead of reset.
173173
void dispose({bool completeDispose = false}) {
174+
log('[Codelessly] Disposing SDK completeDispose: $completeDispose');
174175
if (completeDispose) {
175176
_statusStreamController.close();
176177
} else {

lib/src/codelessly_config.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,40 +115,30 @@ class CodelesslyConfig with EquatableMixin {
115115
];
116116
}
117117

118-
/// SDK initialization state enums.
119-
enum CodelesslyStatus {
120-
/// The SDK has not been initialized.
121-
empty,
122-
123-
/// The SDK has loaded settings and is ready to be initialized.
124-
configured,
118+
sealed class CStatus {
119+
const CStatus();
125120

126-
/// The SDK is initializing.
127-
loading,
121+
factory CStatus.empty() => CEmpty();
128122

129-
/// The SDK is loaded and is ready to use.
130-
loaded,
123+
factory CStatus.configured() => CConfigured();
131124

132-
/// The SDK has an error..
133-
error,
134-
}
125+
factory CStatus.loading(String step) => CLoading(step);
135126

136-
sealed class CStatus {
137-
const CStatus();
127+
factory CStatus.loaded() => CLoaded();
138128

139-
factory CStatus.empty() => const CEmpty();
140-
factory CStatus.configured() => const CConfigured();
141-
factory CStatus.loading(String step) => CLoading(step);
142-
factory CStatus.loaded() => const CLoaded();
143-
factory CStatus.error() => const CError();
129+
factory CStatus.error() => CError();
144130
}
145131

146132
class CEmpty extends CStatus {
147-
const CEmpty();
133+
const CEmpty._();
134+
135+
factory CEmpty() => const CEmpty._();
148136
}
149137

150138
class CConfigured extends CStatus {
151-
const CConfigured();
139+
const CConfigured._();
140+
141+
factory CConfigured() => const CConfigured._();
152142
}
153143

154144
class CLoading extends CStatus {
@@ -158,9 +148,13 @@ class CLoading extends CStatus {
158148
}
159149

160150
class CLoaded extends CStatus {
161-
const CLoaded();
151+
const CLoaded._();
152+
153+
factory CLoaded() => const CLoaded._();
162154
}
163155

164156
class CError extends CStatus {
165-
const CError();
157+
const CError._();
158+
159+
factory CError() => const CError._();
166160
}

lib/src/data/data_manager.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DataManager {
116116

117117
if (_publishModel != null) {
118118
log('[DataManager] Publish model is cached locally. Emitting.');
119-
emitPublishModel();
119+
await emitPublishModel();
120120

121121
loadFontsFromPublishModel();
122122
}
@@ -224,7 +224,7 @@ class DataManager {
224224
log('[DataManager] Publish model is still null during init. Waiting for the first publish model from the server.');
225225
final model = await firstPublishEvent;
226226
_publishModel = model;
227-
emitPublishModel();
227+
await emitPublishModel();
228228
savePublishModel();
229229

230230
log('[DataManager] Publish model during init is now available. Proceeding with init!');
@@ -239,10 +239,6 @@ class DataManager {
239239
}
240240
}
241241

242-
// The PublishModel is guaranteed to be available here. The init exits
243-
// otherwise.
244-
await onPublishModelLoaded(_publishModel!);
245-
246242
// If a [layoutID] was specified, then that layout must be prioritized and
247243
// downloaded first if it is not already cached.
248244
//
@@ -416,7 +412,8 @@ class DataManager {
416412
}
417413

418414
/// Emits the current [_publishModel] to the [_publishModelStreamController].
419-
void emitPublishModel() {
415+
Future<void> emitPublishModel() async {
416+
await onPublishModelLoaded(_publishModel!);
420417
log('[DataManager] Emitting publish model to stream. has model: ${_publishModel != null}');
421418
_publishModelStreamController.add(_publishModel);
422419
}
@@ -444,6 +441,7 @@ class DataManager {
444441

445442
/// Disposes the [DataManager] instance.
446443
void dispose() {
444+
log('[DataManager] Disposing dataManager...');
447445
_publishModelStreamController.close();
448446
_publishModelDocumentListener?.cancel();
449447
initialized = false;
@@ -666,7 +664,7 @@ class DataManager {
666664
}
667665

668666
savePublishModel();
669-
emitPublishModel();
667+
await emitPublishModel();
670668
}
671669

672670
/// Compares the current [localModel] with a newly fetched [serverModel] and
@@ -979,7 +977,7 @@ class DataManager {
979977
log('[DataManager] \tLayout [$layoutID] has no variables.');
980978
}
981979

982-
emitPublishModel();
980+
await emitPublishModel();
983981
savePublishModel();
984982

985983
log('[DataManager] \tLayoutModel [$layoutID] ready, time for fonts. Get Set...');
@@ -1031,9 +1029,8 @@ class DataManager {
10311029

10321030
if (model != null) {
10331031
log('[DataManager] Successfully downloaded complete publish bundle. Emitting it.');
1034-
await onPublishModelLoaded(model);
10351032
_publishModel = model;
1036-
emitPublishModel();
1033+
await emitPublishModel();
10371034
savePublishModel();
10381035
return true;
10391036
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
33

4-
class CodelesslyLoadingScreen extends StatelessWidget {
4+
class CodelesslyLoadingScreen extends StatefulWidget {
55
const CodelesslyLoadingScreen({super.key});
66

77
@override
8-
Widget build(BuildContext context) => const SizedBox.shrink();
8+
State<CodelesslyLoadingScreen> createState() => _CodelesslyLoadingScreenState();
9+
}
10+
11+
class _CodelesslyLoadingScreenState extends State<CodelesslyLoadingScreen> {
12+
@override
13+
Widget build(BuildContext context) => SizedBox.shrink();
914
}

lib/src/ui/codelessly_widget_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class CodelesslyWidgetController extends ChangeNotifier {
175175
// instance, the user explicitly wants more control over the SDK, so we
176176
// do nothing and let the user handle it.
177177
if (isGlobalInstance) {
178-
if (status == const CEmpty()) {
178+
if (status == CEmpty()) {
179179
effectiveCodelessly.configure(
180180
config: config,
181181
authManager: authManager,
@@ -185,7 +185,7 @@ class CodelesslyWidgetController extends ChangeNotifier {
185185
);
186186
}
187187
status = effectiveCodelessly.status;
188-
if (status == const CConfigured()) {
188+
if (status == CConfigured()) {
189189
effectiveCodelessly.initialize();
190190
}
191191
}

lib/src/ui/layout_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _CodelesslyLayoutRetrieverState extends State<CodelesslyLayoutRetriever> {
4444
@override
4545
void dispose() {
4646
controller.dispose();
47-
codelessly.dispose();
47+
codelessly.dispose(completeDispose: true);
4848
super.dispose();
4949
}
5050

0 commit comments

Comments
 (0)