@@ -10,12 +10,17 @@ import 'package:shared_preferences/shared_preferences.dart';
1010
1111import 'homepage.dart' ;
1212
13- class HomePageProjectCreate extends StatelessWidget {
13+ class HomePageProjectCreate extends StatefulWidget {
1414 final Function refreshProjects;
15-
1615 const HomePageProjectCreate ({Key ? key, required this .refreshProjects})
1716 : super (key: key);
1817
18+ @override
19+ State <StatefulWidget > createState () => HomePageProjectCreateState ();
20+
21+ }
22+ class HomePageProjectCreateState extends State <HomePageProjectCreate >{
23+ Widget ? dialog;
1924 Future <SharedPreferences > get _pref async {
2025 return await SharedPreferences .getInstance ();
2126 }
@@ -33,6 +38,73 @@ class HomePageProjectCreate extends StatelessWidget {
3338 style:
3439 const TextStyle (fontSize: 18 , fontWeight: FontWeight .bold))));
3540 for (Template t in m.templates) {
41+ List <Widget > controls = List .empty (growable: true );
42+
43+ /// The options changed later after the window closed
44+ Map <String , dynamic > values = {};
45+
46+ /// Add Options
47+ for (var argName in t.options.keys) {
48+ controls.add (Row (children: [
49+ const Icon (Icons .subdirectory_arrow_right_outlined),
50+ Text (
51+ argName,
52+ textAlign: TextAlign .start,
53+ )
54+ ]));
55+ var optionVal = (t.options[argName] ?? "" );
56+ if (optionVal.startsWith ("String" )) {
57+ var splt = optionVal.split ("|" );
58+ var hint = splt.length > 1 ? splt[1 ] : argName;
59+ controls.add (Padding (
60+ padding: const EdgeInsets .only (bottom: 16.0 ),
61+ child: TextField (
62+ decoration: InputDecoration (hintText: hint),
63+ maxLines: 1 ,
64+ autofocus: true ,
65+ onChanged: (change) {
66+ values[argName] = change;
67+ })));
68+ values[argName] = "" ;
69+ }
70+ }
71+
72+ /// Add Buttons
73+ var row = Row (
74+ mainAxisAlignment: MainAxisAlignment .end,
75+ children: [
76+ TextButton (
77+ child: const Text ("Cancel" ),
78+ onPressed: () {
79+ setState (() {
80+ dialog = null ;
81+ });
82+ },
83+ ),
84+ ElevatedButton (
85+ child: const Text ("Create" ),
86+ onPressed: () async {
87+ /// Go Ahead and create project asynchronously
88+ var slnPath = await t.onCreated (
89+ values); //TODO: This is prone to error (not checking if the file existed first)
90+ if (slnPath == null ) return ;
91+
92+ /// Add it to recent projects
93+ CCSolution ? project =
94+ await RecentProjectsManager .instance.addSolution (slnPath);
95+ if (project != null ) {
96+ await RecentProjectsManager .instance
97+ .commit (SharedPreferences .getInstance ());
98+ //Navigator.pop(context, 3);
99+ //refreshProjects();
100+ loadSolution (project, context);
101+ }
102+ },
103+ )
104+ ],
105+ );
106+ controls.add (row);
107+
36108 /// -------------------------------------------------
37109 /// Project Options
38110 /// -------------------------------------------------
@@ -43,24 +115,30 @@ class HomePageProjectCreate extends StatelessWidget {
43115 subtitle: Text (t.desc),
44116 tileColor: ThemeManager .getThemeData ().backgroundColor,
45117 onTap: () async {
46- Navigator .push (context, MaterialPageRoute (builder: (BuildContext context) => ProjectWizard (t,refreshProjects)));
118+ setState (() {
119+ dialog = ProjectWizard (
120+ t,
121+ children: controls,
122+ );
123+ });
47124 },
48125 )));
49126 }
50127 }
51128 return Scaffold (
52- appBar: AppBar (
53- title: const Center (child: Text ('Create new project' )),
54- ),
55- body: SingleChildScrollView (
56- child: Padding (
57- padding: const EdgeInsets .all (16.0 ),
58- child: Column (
59- children: options,
60- crossAxisAlignment: CrossAxisAlignment .stretch,
61- ))),
62- //contentPadding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
63- backgroundColor: ThemeManager .getThemeData ().canvasColor,
64- );
129+ appBar: AppBar (
130+ title: const Center (child: Text ('Create new project' )),
131+ ),
132+ body: Stack (children: [
133+ SingleChildScrollView (
134+ child: Padding (
135+ padding: const EdgeInsets .all (16.0 ),
136+ child: Column (
137+ children: options,
138+ crossAxisAlignment: CrossAxisAlignment .stretch,
139+ ))),
140+ if (dialog != null )
141+ Positioned .fill (child: dialog! )
142+ ]));
65143 }
66144}
0 commit comments