Skip to content

Commit 98a87ed

Browse files
committed
fix: change writeDemoDocument to synchronous
1 parent adcc915 commit 98a87ed

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

mobile-app/lib/ui/views/learn/challenge/challenge_viewmodel.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ class ChallengeViewModel extends BaseViewModel {
520520
return document;
521521
}
522522

523-
Future<String> writeDemoDocument(
524-
String doc, List<List<SolutionFile>>? solutions) async {
523+
String writeDemoDocument(String doc, List<List<SolutionFile>>? solutions) {
525524
if (solutions == null || solutions.isEmpty) {
526525
return parse(doc).outerHtml;
527526
}
@@ -560,26 +559,25 @@ class ChallengeViewModel extends BaseViewModel {
560559
}
561560

562561
String viewPort = '''<meta content="width=device-width,
563-
initial-scale=1.0, maximum-scale=1.0,
564-
user-scalable=no" name="viewport">
565-
<meta>''';
562+
initial-scale=1.0, maximum-scale=1.0,
563+
user-scalable=no" name="viewport">
564+
<meta>''';
566565
Document viewPortParsed = parse(viewPort);
567566
Node meta = viewPortParsed.getElementsByTagName('META')[0];
568567
document.getElementsByTagName('HEAD')[0].append(meta);
569568

570569
return document.outerHtml;
571570
}
572571

573-
Future<String?> provideDemo(List<List<SolutionFile>>? solutions) async {
574-
// Use the first solution's HTML file as the base doc
572+
String? provideDemo(List<List<SolutionFile>>? solutions) {
575573
if (solutions == null || solutions.isEmpty) {
576574
return null;
577575
}
578576

579577
List<SolutionFile> htmlFiles =
580578
solutions[0].where((file) => file.ext == 'html').toList();
581579
String doc = htmlFiles.isNotEmpty ? htmlFiles[0].contents : '';
582-
String document = await writeDemoDocument(doc, solutions);
580+
String document = writeDemoDocument(doc, solutions);
583581

584582
return document;
585583
}

mobile-app/lib/ui/views/learn/widgets/challenge_widgets/project_demo.dart

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,26 @@ class ProjectDemo extends StatelessWidget {
3636
],
3737
),
3838
Expanded(
39-
child: FutureBuilder(
40-
future: model.provideDemo(solutions),
41-
builder: (context, snapshot) {
42-
if (snapshot.hasData) {
43-
if (snapshot.data is String) {
44-
return InAppWebView(
45-
initialData: InAppWebViewInitialData(
46-
data: snapshot.data as String,
47-
mimeType: 'text/html',
48-
),
49-
onWebViewCreated: (controller) {
50-
model.setWebviewController = controller;
51-
},
52-
initialSettings: InAppWebViewSettings(
53-
// TODO: Set this to true only in dev mode
54-
isInspectable: true,
55-
),
56-
);
57-
}
58-
}
59-
60-
if (snapshot.hasError) {
61-
return Center(
62-
child: Text(context.t.error),
39+
child: Builder(
40+
builder: (context) {
41+
final html = model.provideDemo(solutions);
42+
if (html != null) {
43+
return InAppWebView(
44+
initialData: InAppWebViewInitialData(
45+
data: html,
46+
mimeType: 'text/html',
47+
),
48+
onWebViewCreated: (controller) {
49+
model.setWebviewController = controller;
50+
},
51+
initialSettings: InAppWebViewSettings(
52+
// TODO: Set this to true only in dev mode
53+
isInspectable: true,
54+
),
6355
);
6456
}
65-
6657
return const Center(
67-
child: CircularProgressIndicator(),
58+
child: Text('No demo available'),
6859
);
6960
},
7061
),

0 commit comments

Comments
 (0)