Skip to content

Commit 96c45f2

Browse files
committed
Project creation dialog is now a screen
1 parent 68fa88a commit 96c45f2

File tree

2 files changed

+99
-80
lines changed

2 files changed

+99
-80
lines changed

lib/screens/homepage/homepage_project_create.dart

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:io';
2+
import 'package:corecoder_develop/screens/homepage/homepage_project_wizard.dart';
23
import 'package:corecoder_develop/util/cc_project_structure.dart';
34
import 'package:corecoder_develop/util/modules_manager.dart';
45
import 'package:corecoder_develop/util/theme_manager.dart';
@@ -42,86 +43,7 @@ class HomePageProjectCreate extends StatelessWidget {
4243
subtitle: Text(t.desc),
4344
tileColor: ThemeManager.getThemeData().backgroundColor,
4445
onTap: () async {
45-
/// The options changed later after the window closed
46-
Map<String, dynamic> values = {};
47-
await showDialog<int>(
48-
context: context,
49-
builder: (BuildContext context) {
50-
List<Widget> controls = List.empty(growable: true);
51-
52-
/// Add Options
53-
for (var argName in t.options.keys) {
54-
controls.add(Row(children: [
55-
const Icon(Icons.subdirectory_arrow_right_outlined),
56-
Text(
57-
argName,
58-
textAlign: TextAlign.start,
59-
)
60-
]));
61-
var optionVal = (t.options[argName] ?? "");
62-
if (optionVal.startsWith("String")) {
63-
var splt = optionVal.split("|");
64-
var hint = splt.length > 1? splt[1] : argName;
65-
controls.add(Padding(
66-
padding: const EdgeInsets.only(bottom: 16.0),
67-
child: TextField(
68-
decoration: InputDecoration(hintText: hint),
69-
maxLines: 1,
70-
autofocus: true,
71-
onChanged: (change) {
72-
values[argName] = change;
73-
})));
74-
values[argName] = "";
75-
}
76-
}
77-
78-
/// Add Buttons
79-
var row = Row(
80-
mainAxisAlignment: MainAxisAlignment.end,
81-
children: [
82-
TextButton(
83-
child: const Text("Cancel"),
84-
onPressed: () {
85-
Navigator.pop(context, 1);
86-
},
87-
),
88-
ElevatedButton(
89-
child: const Text("Create"),
90-
onPressed: () async {
91-
/// Go Ahead and create project asynchronously
92-
var slnPath = await t.onCreated(
93-
values); //TODO: This is prone to error (not checking if the file existed first)
94-
if (slnPath == null) return;
95-
96-
/// Add it to recent projects
97-
CCSolution? project = await RecentProjectsManager
98-
.instance
99-
.addSolution(slnPath);
100-
if (project != null) {
101-
await RecentProjectsManager.instance.commit(_pref);
102-
Navigator.pop(context, 3);
103-
refreshProjects();
104-
loadSolution(project, context);
105-
}
106-
},
107-
)
108-
],
109-
);
110-
controls.add(row);
111-
// Return the dialog to be opened
112-
return SimpleDialog(
113-
title: Text('Create ${t.title}'),
114-
children: <Widget>[
115-
Padding(
116-
padding: const EdgeInsets.symmetric(horizontal: 16.0),
117-
child: Column(
118-
children: controls,
119-
crossAxisAlignment: CrossAxisAlignment.stretch,
120-
))
121-
],
122-
);
123-
},
124-
barrierDismissible: true);
46+
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => ProjectWizard(t,refreshProjects)));
12547
},
12648
)));
12749
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import 'package:corecoder_develop/util/cc_project_structure.dart';
2+
import 'package:corecoder_develop/util/modules_manager.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:shared_preferences/shared_preferences.dart';
5+
6+
import 'homepage.dart';
7+
8+
class ProjectWizard extends StatelessWidget {
9+
final Template template;
10+
final Function refreshProjects;
11+
12+
const ProjectWizard(this.template, this.refreshProjects, {Key? key}) : super(key: key);
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
17+
List<Widget> controls = List.empty(growable: true);
18+
/// The options changed later after the window closed
19+
Map<String, dynamic> values = {};
20+
21+
/// Add Options
22+
for (var argName in template.options.keys) {
23+
controls.add(Row(children: [
24+
const Icon(Icons.subdirectory_arrow_right_outlined),
25+
Text(
26+
argName,
27+
textAlign: TextAlign.start,
28+
)
29+
]));
30+
var optionVal = (template.options[argName] ?? "");
31+
if (optionVal.startsWith("String")) {
32+
var splt = optionVal.split("|");
33+
var hint = splt.length > 1? splt[1] : argName;
34+
controls.add(Padding(
35+
padding: const EdgeInsets.only(bottom: 16.0),
36+
child: TextField(
37+
decoration: InputDecoration(hintText: hint),
38+
maxLines: 1,
39+
autofocus: true,
40+
onChanged: (change) {
41+
values[argName] = change;
42+
})));
43+
values[argName] = "";
44+
}
45+
}
46+
47+
/// Add Buttons
48+
var row = Row(
49+
mainAxisAlignment: MainAxisAlignment.end,
50+
children: [
51+
TextButton(
52+
child: const Text("Cancel"),
53+
onPressed: () {
54+
Navigator.pop(context, 1);
55+
},
56+
),
57+
ElevatedButton(
58+
child: const Text("Create"),
59+
onPressed: () async {
60+
/// Go Ahead and create project asynchronously
61+
var slnPath = await template.onCreated(
62+
values); //TODO: This is prone to error (not checking if the file existed first)
63+
if (slnPath == null) return;
64+
65+
/// Add it to recent projects
66+
CCSolution? project = await RecentProjectsManager
67+
.instance
68+
.addSolution(slnPath);
69+
if (project != null) {
70+
await RecentProjectsManager.instance.commit(SharedPreferences.getInstance());
71+
Navigator.pop(context, 3);
72+
refreshProjects();
73+
loadSolution(project, context);
74+
}
75+
},
76+
)
77+
],
78+
);
79+
controls.add(row);
80+
81+
return Scaffold(
82+
appBar: AppBar(
83+
title: Text('Create ${template.title}'),
84+
),
85+
body: SingleChildScrollView(
86+
child: Column(
87+
children: <Widget>[
88+
Padding(
89+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
90+
child: Column(
91+
children: controls,
92+
crossAxisAlignment: CrossAxisAlignment.stretch,
93+
))
94+
],
95+
)));
96+
}
97+
}

0 commit comments

Comments
 (0)