Skip to content

Commit 1c7f8d2

Browse files
committed
refactor: update ListView in BlockListView to include progress indicator and toggle button;
1 parent a440a44 commit 1c7f8d2

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

mobile-app/lib/ui/views/learn/block/templates/list/list_view.dart

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:flutter/widgets.dart';
1+
import 'package:flutter/material.dart';
22
import 'package:freecodecamp/models/learn/curriculum_model.dart';
33
import 'package:freecodecamp/ui/views/learn/block/block_template_viewmodel.dart';
44
import 'package:freecodecamp/ui/views/learn/block/templates/grid/grid_viewmodel.dart';
@@ -16,9 +16,102 @@ class BlockListView extends StatelessWidget {
1616

1717
@override
1818
Widget build(BuildContext context) {
19+
double progress = model.challengesCompleted == 0
20+
? 0.01
21+
: model.challengesCompleted / block.challenges.length;
1922
return ViewModelBuilder.reactive(
2023
viewModelBuilder: () => BlockGridViewModel(),
21-
builder: (context, childModel, child) => const Text('list view'),
24+
builder: (context, childModel, child) => Column(
25+
crossAxisAlignment: CrossAxisAlignment.start,
26+
children: [
27+
SizedBox(
28+
// For some dumb reason the progress indicator does not
29+
// get a specified width from the column.
30+
width: MediaQuery.of(context).size.width * 0.7725,
31+
child: LinearProgressIndicator(
32+
minHeight: 10,
33+
value: progress,
34+
valueColor: const AlwaysStoppedAnimation<Color>(
35+
Color.fromRGBO(0x99, 0xc9, 0xff, 1),
36+
),
37+
backgroundColor: const Color.fromRGBO(0x2a, 0x2a, 0x40, 1),
38+
borderRadius: BorderRadius.circular(10),
39+
),
40+
),
41+
Row(
42+
children: [
43+
Padding(
44+
padding: const EdgeInsets.symmetric(
45+
vertical: 4,
46+
),
47+
child: TextButton(
48+
onPressed: () {
49+
model.setIsOpen = !model.isOpen;
50+
},
51+
style: TextButton.styleFrom(
52+
backgroundColor: const Color.fromRGBO(0x1b, 0x1b, 0x32, 1),
53+
shape: RoundedRectangleBorder(
54+
borderRadius: BorderRadius.circular(5),
55+
side: const BorderSide(
56+
color: Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
57+
),
58+
),
59+
),
60+
child: Text(
61+
model.isOpen ? 'Hide' : 'Show',
62+
),
63+
),
64+
),
65+
],
66+
),
67+
if (model.isOpen)
68+
Row(
69+
children: [
70+
SizedBox(
71+
width: MediaQuery.of(context).size.width * 0.7725,
72+
child: ListView.builder(
73+
shrinkWrap: true,
74+
physics: const ClampingScrollPhysics(),
75+
itemCount: block.challenges.length,
76+
itemBuilder: (context, index) {
77+
bool isCompleted =
78+
model.completedChallenge(block.challenges[index].id);
79+
80+
return InkWell(
81+
onTap: () {
82+
model.routeToChallengeView(
83+
block,
84+
block.challenges[index].id,
85+
);
86+
},
87+
child: Card(
88+
shape: RoundedRectangleBorder(
89+
borderRadius: BorderRadius.circular(5),
90+
side: isCompleted
91+
? const BorderSide(
92+
width: 1,
93+
color: Color.fromRGBO(0xbc, 0xe8, 0xf1, 1),
94+
)
95+
: const BorderSide(
96+
color: Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
97+
),
98+
),
99+
color: isCompleted
100+
? const Color.fromRGBO(0x00, 0x2e, 0xad, 0.3)
101+
: const Color.fromRGBO(0x2a, 0x2a, 0x40, 1),
102+
child: Padding(
103+
padding: const EdgeInsets.all(8.0),
104+
child: Text(block.challenges[index].title),
105+
),
106+
),
107+
);
108+
},
109+
),
110+
),
111+
],
112+
),
113+
],
114+
),
22115
);
23116
}
24117
}

mobile-app/lib/ui/views/learn/superblock/superblock_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SuperBlockView extends StatelessWidget {
8585
children: [
8686
BlockTemplateView(
8787
block: superBlock.blocks![i],
88-
isOpen: superBlock.blocks!.length <= 5,
88+
isOpen: superBlock.blocks!.length <= 3,
8989
)
9090
],
9191
),

0 commit comments

Comments
 (0)