Skip to content

Commit 69656e1

Browse files
committed
Refactor: Project item is now a separate widget
1 parent b44192c commit 69656e1

File tree

2 files changed

+94
-73
lines changed

2 files changed

+94
-73
lines changed

lib/screens/homepage/homepage.dart

Lines changed: 29 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:ffi';
12
import 'dart:io';
23

34
import 'package:corecoder_develop/filebrowser/utils/utils.dart';
@@ -221,84 +222,39 @@ class _HomePageState extends State<HomePage> {
221222

222223
List<Widget> get projectsWidgetList {
223224
var result = <Widget>[];
225+
226+
/// The create button
227+
result.add(ProjectItem(
228+
isListView: isListView, menuButton: null,
229+
icon: const Icon(Icons.add, size: 48,),
230+
title: "Create project", subtitle: "",
231+
onPressed: ()=>showCreateProjectDialog()));
232+
224233
for (HistoryItem p in RecentProjectsManager.instance.projects) {
225234
// if (p.name == "") {
226235
// continue;
227236
// } // TODO: add better way to check if project is corrupt
228237
//debugPrint(p.name);
229-
result.add(Card(
230-
//TODO: refactor this as a widget elsewhere, then reference that widget from here
231-
child: isListView
232-
? ListTile(
233-
shape: RoundedRectangleBorder(
234-
borderRadius: BorderRadius.circular(4),
235-
side: BorderSide(color: Theme.of(context).dividerColor),
236-
),
237-
onTap: () => onHistoryItemTap(p),
238-
leading: p.type == HistoryItemType.solution
239-
? p.solution!.image ??
240-
const Icon(
241-
Icons.insert_drive_file,
242-
size: 48,
243-
)
244-
: const Icon(
245-
Icons.insert_drive_file,
246-
size: 48,
247-
),
248-
title: Text(
249-
p.name,
250-
style: const TextStyle(fontWeight: FontWeight.bold),
251-
),
252-
subtitle: Text("Last Modified: " +
253-
Utils.getFormattedDateTime(dateTime: p.dateModified)),
254-
trailing: PopupMenuButton<String>(
255-
onSelected: (String result) =>
256-
onMenuItemSelected(result, p),
257-
itemBuilder: (BuildContext context) => getPopupMenu(p)))
258-
: SizedBox(
259-
width: 128,
260-
height: 128,
261-
child: OutlinedButton(
262-
onPressed: () => onHistoryItemTap(p),
263-
child: Stack(children: [
264-
Column(
265-
mainAxisAlignment: MainAxisAlignment.center,
266-
children: [
267-
p.type == HistoryItemType.solution
268-
? p.solution!.image ??
269-
const Icon(
270-
Icons.insert_drive_file,
271-
size: 48,
272-
)
273-
: const Icon(
274-
Icons.insert_drive_file,
275-
size: 48,
276-
),
277-
const SizedBox(height: 8,),
278-
Text(
279-
p.name,
280-
style: TextStyle(
281-
color: Theme.of(context)
282-
.textTheme
283-
.bodyText1!
284-
.color!,
285-
fontSize: 12.0),
286-
),
287-
Text(
288-
Utils.getFormattedDateTime(
289-
dateTime: p.dateModified),
290-
style: TextStyle(
291-
color: Theme.of(context).focusColor,
292-
fontSize: 12.0),
293-
)
294-
],
295-
),
296-
Positioned(
297-
top: 0,right: -16,
298-
child: PopupMenuButton<String>(
299-
onSelected: (String result) => onMenuItemSelected(result, p),
300-
itemBuilder: (BuildContext context) => getPopupMenu(p)))
301-
])))));
238+
result.add(ProjectItem(
239+
isListView: isListView,
240+
menuButton: PopupMenuButton<String>(
241+
onSelected: (String result) =>
242+
onMenuItemSelected(result, p),
243+
itemBuilder: (BuildContext context) => getPopupMenu(p)),
244+
icon: p.type == HistoryItemType.solution
245+
? p.solution!.image ??
246+
const Icon(
247+
Icons.insert_drive_file,
248+
size: 48,
249+
)
250+
: const Icon(
251+
Icons.insert_drive_file,
252+
size: 48,
253+
),
254+
title: p.name,
255+
subtitle: "Last Modified: " +
256+
Utils.getFormattedDateTime(dateTime: p.dateModified),
257+
onPressed:()=> onHistoryItemTap(p)));
302258
}
303259
return result;
304260
}

lib/screens/homepage/homepage_projectlist.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,68 @@ class ProjectList extends StatelessWidget {
8888
])));
8989
}
9090
}
91+
92+
class ProjectItem extends StatelessWidget{
93+
final bool isListView;
94+
final Widget icon;
95+
final String title,subtitle;
96+
final Function onPressed;
97+
final Widget? menuButton;
98+
99+
const ProjectItem({Key? key, required this.isListView, required this.menuButton,
100+
required this.icon, required this.title, required this.subtitle, required this.onPressed}) : super(key: key);
101+
102+
@override
103+
Widget build(BuildContext context) {
104+
return Card(
105+
//TODO: refactor this as a widget elsewhere, then reference that widget from here
106+
child: isListView
107+
? ListTile(
108+
shape: RoundedRectangleBorder(
109+
borderRadius: BorderRadius.circular(4),
110+
side: BorderSide(color: Theme.of(context).dividerColor),
111+
),
112+
onTap: () => onPressed(),
113+
leading: icon,
114+
title: Text(
115+
title,
116+
style: const TextStyle(fontWeight: FontWeight.bold),
117+
),
118+
trailing: menuButton,
119+
subtitle: (subtitle != "" ? Text(subtitle) : null))
120+
: SizedBox(
121+
width: 128,
122+
height: 128,
123+
child: OutlinedButton(
124+
onPressed: () => onPressed(),
125+
child: Stack(children: [
126+
Column(
127+
mainAxisAlignment: MainAxisAlignment.center,
128+
children: [
129+
icon,
130+
const SizedBox(height: 8,),
131+
Text(
132+
title,
133+
style: TextStyle(
134+
color: Theme.of(context)
135+
.textTheme
136+
.bodyText1!
137+
.color!,
138+
fontSize: 12.0),
139+
),
140+
if(subtitle != "")
141+
Text(subtitle,
142+
style: TextStyle(
143+
color: Theme.of(context).focusColor,
144+
fontSize: 12.0),
145+
)
146+
],
147+
),
148+
if(menuButton != null)
149+
Positioned(
150+
top: 0,right: -16,
151+
child: menuButton!)
152+
]))));
153+
}
154+
155+
}

0 commit comments

Comments
 (0)