Skip to content

Commit

Permalink
Merge pull request #316 from saisurendra6/main
Browse files Browse the repository at this point in the history
outreachy scroll view bug fixed
  • Loading branch information
andoriyaprashant authored Aug 14, 2024
2 parents 787fe66 + 89c56b2 commit 2fc7096
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions lib/programs screen/outreachy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
List<OutreachyProjectModal> outreachy2023 = [];
List<OutreachyProjectModal> outreachy2022 = [];
List<OutreachyProjectModal> outreachy2021 = [];
bool isBookmarked = false;
bool isBookmarked = false;
bool isBookmarkEnabled = false;
List<String> allSkills = [];
List<String> selectedSkills = ['All'];
Expand All @@ -34,21 +34,28 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
Future<void>? getProjectFunction;

Future<void> initializeProjectLists() async {
await _loadProjects('assets/projects/outreachy/outreachy2024.json', outreachy2024);
await _loadProjects('assets/projects/outreachy/outreachy2023.json', outreachy2023);
await _loadProjects('assets/projects/outreachy/outreachy2022.json', outreachy2022);
await _loadProjects('assets/projects/outreachy/outreachy2021.json', outreachy2021);
await _loadProjects(
'assets/projects/outreachy/outreachy2024.json', outreachy2024);
await _loadProjects(
'assets/projects/outreachy/outreachy2023.json', outreachy2023);
await _loadProjects(
'assets/projects/outreachy/outreachy2022.json', outreachy2022);
await _loadProjects(
'assets/projects/outreachy/outreachy2021.json', outreachy2021);

allSkills = _extractUniqueSkills();
projectList = List.from(outreachy2021);
}

Future<void> _loadProjects(String path, List<OutreachyProjectModal> list) async {
Future<void> _loadProjects(
String path, List<OutreachyProjectModal> list) async {
try {
String response = await rootBundle.loadString(path);
if (response.isNotEmpty) {
var jsonList = json.decode(response) as List;
list.addAll(jsonList.map((data) => OutreachyProjectModal.fromMap(data)).toList());
list.addAll(jsonList
.map((data) => OutreachyProjectModal.fromMap(data))
.toList());
print('Loaded projects from $path: ${list.length}');
} else {
print('Error: JSON data is null or empty in $path');
Expand All @@ -68,8 +75,6 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
}.toSet().toList();
}



List<OutreachyProjectModal> _getProjectsByYear() {
switch (selectedYear) {
case 2021:
Expand All @@ -89,8 +94,10 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
projectList = _getProjectsByYear();

if (!selectedSkills.contains('All')) {
projectList = projectList.where((project) =>
project.skills.any((skill) => selectedSkills.contains(skill))).toList();
projectList = projectList
.where((project) =>
project.skills.any((skill) => selectedSkills.contains(skill)))
.toList();
}

setState(() {});
Expand Down Expand Up @@ -142,7 +149,8 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'),
content: Text(
isBookmarked ? 'Bookmark added' : 'Bookmark removed'),
duration: const Duration(seconds: 2),
),
);
Expand All @@ -158,7 +166,8 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => OUTREACHYInfo()), );
MaterialPageRoute(builder: (context) => OUTREACHYInfo()),
);
},
),
]),
Expand All @@ -170,7 +179,8 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
} else if (snapshot.connectionState == ConnectionState.done) {
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expand All @@ -183,13 +193,14 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
buttonText: "Filter by Skill",
onConfirm: (results) {
setState(() {
selectedSkills = results.isNotEmpty ? results : ['All'];
selectedSkills =
results.isNotEmpty ? results : ['All'];
filterProjects();
});
},
),
const SizedBox(height: 20),
_buildProjectList(height, width),
..._projectListItems(height, width),
],
),
),
Expand Down Expand Up @@ -224,8 +235,9 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
filterProjects();
});
},
backgroundColor:
selectedYear == 2021 ? Colors.white : Color.fromRGBO(255, 183, 77, 1),
backgroundColor: selectedYear == 2021
? Colors.white
: Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
year: "2022",
Expand All @@ -236,8 +248,9 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
filterProjects();
});
},
backgroundColor:
selectedYear == 2022 ? Colors.white : Color.fromRGBO(255, 183, 77, 1),
backgroundColor: selectedYear == 2022
? Colors.white
: Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
year: "2023",
Expand All @@ -248,8 +261,9 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
filterProjects();
});
},
backgroundColor:
selectedYear == 2023 ? Colors.white : Color.fromRGBO(255, 183, 77, 1),
backgroundColor: selectedYear == 2023
? Colors.white
: Color.fromRGBO(255, 183, 77, 1),
),
YearButton(
year: "2024",
Expand All @@ -260,8 +274,9 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
filterProjects();
});
},
backgroundColor:
selectedYear == 2024 ? Colors.white : Color.fromRGBO(255, 183, 77, 1),
backgroundColor: selectedYear == 2024
? Colors.white
: Color.fromRGBO(255, 183, 77, 1),
),
],
),
Expand Down Expand Up @@ -290,23 +305,18 @@ class _OutreachyScreenState extends State<OutreachyScreen> {
);
}

Widget _buildProjectList(double height, double width) {
return SizedBox(
height: height,
child: ListView.builder(
itemCount: projectList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: OutreachyProjectWidget(
modal: projectList[index],
index: index + 1,
height: height * 0.2,
width: width,
),
);
},
List _projectListItems(double height, double width) {
return List.generate(
projectList.length,
(index) => Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: OutreachyProjectWidget(
modal: projectList[index],
index: index + 1,
height: height * 0.2,
width: width,
),
),
);
}
}
}

0 comments on commit 2fc7096

Please sign in to comment.