diff --git a/lib/programs screen/girl_script.dart b/lib/programs screen/girl_script.dart index 34bdb6d..8ea149d 100644 --- a/lib/programs screen/girl_script.dart +++ b/lib/programs screen/girl_script.dart @@ -1,22 +1,26 @@ import 'dart:convert'; - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:opso/modals/book_mark_model.dart'; import 'package:opso/modals/gssoc_project_modal.dart'; + import 'package:opso/widgets/gssoc_project_widget.dart'; import 'package:opso/widgets/year_button.dart'; + import '../widgets/SearchandFilterWidget.dart'; + class GSSOCScreen extends StatefulWidget { const GSSOCScreen({super.key}); + @override State createState() => _GSSOCScreenState(); } + class _GSSOCScreenState extends State { String currectPage = "/girl_script_summer_of_code"; String currentProject = "Girl Script Summer of Code"; @@ -26,38 +30,40 @@ class _GSSOCScreenState extends State { List gssoc2022 = []; List gssoc2021 = []; int selectedYear = 2024; - + String selectedOrg = "All"; List projectList = []; Future? getProjectFunction; + Future initializeProjectLists() async { String response = - await rootBundle.loadString('assets/projects/gssoc/gssoc2024.json'); + await rootBundle.loadString('assets/projects/gssoc/gssoc2024.json'); var jsonList = await json.decode(response); for (var data in jsonList) { gssoc2024.add(GssocProjectModal.getDataFromJson(data)); } projectList = List.from(gssoc2024); response = - await rootBundle.loadString('assets/projects/gssoc/gssoc2023.json'); + await rootBundle.loadString('assets/projects/gssoc/gssoc2023.json'); jsonList = await json.decode(response); for (var data in jsonList) { gssoc2023.add(GssocProjectModal.getDataFromJson(data)); } response = - await rootBundle.loadString('assets/projects/gssoc/gssoc2022.json'); + await rootBundle.loadString('assets/projects/gssoc/gssoc2022.json'); jsonList = await json.decode(response); for (var data in jsonList) { gssoc2022.add(GssocProjectModal.getDataFromJson(data)); } response = - await rootBundle.loadString('assets/projects/gssoc/gssoc2021.json'); + await rootBundle.loadString('assets/projects/gssoc/gssoc2021.json'); jsonList = await json.decode(response); for (var data in jsonList) { gssoc2021.add(GssocProjectModal.getDataFromJson(data)); } } + @override void initState() { getProjectFunction = initializeProjectLists(); @@ -65,6 +71,7 @@ class _GSSOCScreenState extends State { _checkBookmarkStatus(); } + Future _checkBookmarkStatus() async { bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProject); setState(() { @@ -72,6 +79,7 @@ class _GSSOCScreenState extends State { }); } + void searchTag(String searchTag) { projectList = projectList .where((element) => element.techstack.contains(searchTag)) @@ -79,6 +87,7 @@ class _GSSOCScreenState extends State { setState(() {}); } + void search(String searchText) { if (searchText.isEmpty) { switch (selectedYear) { @@ -101,19 +110,29 @@ class _GSSOCScreenState extends State { projectList = projectList .where( (element) => - element.name.toLowerCase().contains(searchText.toLowerCase()) || - element.techstack.contains(searchText) || - element.hostedBy.toLowerCase().contains(searchText.toLowerCase()), - ) + element.name.toLowerCase().contains(searchText.toLowerCase()) || + element.techstack.contains(searchText) || + element.hostedBy.toLowerCase().contains(searchText.toLowerCase()), + ) .toList(); setState(() {}); } + + Future _refresh() async { + setState(() { + initializeProjectLists(); + selectedYear = 2024; + }); + } + + @override Widget build(BuildContext context) { var height = MediaQuery.sizeOf(context).height; var width = MediaQuery.sizeOf(context).width; List languages = [ + 'All', 'Js', 'Python', 'React', @@ -130,254 +149,258 @@ class _GSSOCScreenState extends State { 'Flutter', 'Dart' ]; - return Scaffold( - - appBar: AppBar( - title: const Text('OpSo'), - actions: [ + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + appBar: AppBar(title: const Text('GSSoC'), actions: [ IconButton( - icon: (isBookmarked) - ? const Icon(Icons.bookmark_add_rounded) - : const Icon(Icons.bookmark_add_outlined), - onPressed: () { - setState(() { - isBookmarked = !isBookmarked; - }); - ScaffoldMessenger.of(context).showSnackBar( + icon: (isBookmarked) + ? const Icon(Icons.bookmark_add_rounded) + : const Icon(Icons.bookmark_add_outlined), + onPressed: () { + setState(() { + isBookmarked = !isBookmarked; + }); + ScaffoldMessenger.of(context).showSnackBar( SnackBar( - content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), - duration: const Duration(seconds: 2), // Adjust the duration as needed + content: Text( + isBookmarked ? 'Bookmark added' : 'Bookmark removed'), + duration: const Duration( + seconds: 2), // Adjust the duration as needed ), ); - if(isBookmarked){ - print("Adding"); - HandleBookmark.addBookmark(currentProject, currectPage); - } - else{ - print("Deleting"); - HandleBookmark.deleteBookmark(currentProject); - } - }, + if (isBookmarked) { + print("Adding"); + HandleBookmark.addBookmark(currentProject, currectPage); + } else { + print("Deleting"); + HandleBookmark.deleteBookmark(currentProject); + } + }, ) - ] - ), - - body: FutureBuilder( - future: getProjectFunction, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.connectionState == ConnectionState.done) { - return Padding( - padding: + ]), + body: FutureBuilder( + future: getProjectFunction, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.connectionState == ConnectionState.done) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - TextFormField( - decoration: InputDecoration( - filled: true, - // fillColor: const Color(0xFFEEEEEE), - hintText: 'Search', - suffixIcon: const Icon(Icons.search), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), - ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), - ), - ), - disabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), - ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + TextFormField( + decoration: InputDecoration( + filled: true, + // fillColor: const Color(0xFFEEEEEE), + hintText: 'Search', + suffixIcon: const Icon(Icons.search), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), + ), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), + ), + contentPadding: const EdgeInsets.symmetric( + vertical: 12.0, horizontal: 20.0), ), + onFieldSubmitted: (value) { + print("value is $value"); + search(value.trim()); + }, + onChanged: (value) { + if (value.isEmpty) { + search(value); + } + }, ), - contentPadding: const EdgeInsets.symmetric( - vertical: 12.0, horizontal: 20.0), - ), - onFieldSubmitted: (value) { - print("value is $value"); - search(value.trim()); - }, - onChanged: (value) { - if (value.isEmpty) { - search(value); - } - }, - ), - const SizedBox(height: 20), - SizedBox( - height: height * 0.2, - width: width, - child: GridView( - physics: const NeverScrollableScrollPhysics(), - gridDelegate: + const SizedBox(height: 20), + SizedBox( + height: height * 0.2, + width: width, + child: GridView( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - childAspectRatio: 1.5 / 0.6, - crossAxisSpacing: 15, - mainAxisSpacing: 15, - ), - children: [ - YearButton( - year: "2021", - isEnabled: selectedYear == 2021 ? true : false, - onTap: () { - setState(() { - projectList = gssoc2021; - selectedYear = 2021; - }); - }, - backgroundColor: selectedYear == 2021 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2022", - isEnabled: selectedYear == 2022 ? true : false, - onTap: () { - setState(() { - projectList = gssoc2022; - selectedYear = 2022; - }); - }, - backgroundColor: selectedYear == 2022 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2023", - isEnabled: selectedYear == 2023 ? true : false, - onTap: () { - setState(() { - projectList = gssoc2023; - selectedYear = 2023; - }); - }, - backgroundColor: selectedYear == 2023 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - isEnabled: selectedYear == 2024 ? true : false, - year: "2024", - onTap: () { - setState(() { - projectList = gssoc2024; - selectedYear = 2024; - }); - }, - backgroundColor: selectedYear == 2024 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - ], - ), - ), - // const SizedBox(height: 20), - // SizedBox( - // height: 50, - // child: ElevatedButton( - // onPressed: () {}, - // style: ElevatedButton.styleFrom( - // shape: const RoundedRectangleBorder( - // borderRadius: BorderRadius.zero, - // ), - // backgroundColor: const Color.fromARGB( - // 255, 253, 214, 115), // Set button color - // padding: const EdgeInsets.symmetric( - // vertical: 10.0, horizontal: 20.0), - // ), - // child: const Text( - // 'View Projects', - // style: TextStyle(color: Colors.white, fontSize: 18), - // ), - // ), - // ), - const SizedBox( - height: 20, - ), - - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - const Text( - 'Filter by Language:', - style: TextStyle(fontWeight: FontWeight.w400), - ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisCount: 2, + childAspectRatio: 1.5 / 0.6, + crossAxisSpacing: 15, + mainAxisSpacing: 15, + ), children: [ - DropdownWidget( - items: languages, - hintText: 'Language', - onChanged: (newValue) { + YearButton( + year: "2021", + isEnabled: selectedYear == 2021 ? true : false, + onTap: () { + setState(() { + projectList = gssoc2021; + selectedYear = 2021; + }); + }, + backgroundColor: selectedYear == 2021 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2022", + isEnabled: selectedYear == 2022 ? true : false, + onTap: () { + setState(() { + projectList = gssoc2022; + selectedYear = 2022; + }); + }, + backgroundColor: selectedYear == 2022 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2023", + isEnabled: selectedYear == 2023 ? true : false, + onTap: () { + setState(() { + projectList = gssoc2023; + selectedYear = 2023; + }); + }, + backgroundColor: selectedYear == 2023 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + isEnabled: selectedYear == 2024 ? true : false, + year: "2024", + onTap: () { setState(() { - switch (selectedYear) { - case 2021: - projectList = gssoc2021; - break; - case 2022: - projectList = gssoc2022; - break; - case 2023: - projectList = gssoc2023; - break; - case 2024: - projectList = gssoc2024; - break; - } - searchTag(newValue); + projectList = gssoc2024; + selectedYear = 2024; }); - // Perform filtering based on selectedLanguage }, + backgroundColor: selectedYear == 2024 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), ), ], ), - ) - ], - ), + ), + // const SizedBox(height: 20), + // SizedBox( + // height: 50, + // child: ElevatedButton( + // onPressed: () {}, + // style: ElevatedButton.styleFrom( + // shape: const RoundedRectangleBorder( + // borderRadius: BorderRadius.zero, + // ), + // backgroundColor: const Color.fromARGB( + // 255, 253, 214, 115), // Set button color + // padding: const EdgeInsets.symmetric( + // vertical: 10.0, horizontal: 20.0), + // ), + // child: const Text( + // 'View Projects', + // style: TextStyle(color: Colors.white, fontSize: 18), + // ), + // ), + // ), + const SizedBox( + height: 20, + ), + - Expanded( - // width: width, - child: ListView.builder( - itemCount: projectList.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 10), - child: GssocProjectWidget( - index: index + 1, - modal: projectList[index], - height: height * 0.2, - width: width, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + const Text( + 'Filter by Language:', + style: TextStyle(fontWeight: FontWeight.w400), ), - ); - }, - ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + DropdownWidget( + items: languages, + hintText: 'Language', + onChanged: (newValue) { + setState(() { + switch (selectedYear) { + case 2021: + projectList = gssoc2021; + break; + case 2022: + projectList = gssoc2022; + break; + case 2023: + projectList = gssoc2023; + break; + case 2024: + projectList = gssoc2024; + break; + } + searchTag(newValue); + }); + // Perform filtering based on selectedLanguage + }, + ), + ], + ), + ) + ], + ), + + + Expanded( + // width: width, + child: ListView.builder( + itemCount: projectList.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: GssocProjectWidget( + index: index + 1, + modal: projectList[index], + height: height * 0.2, + width: width, + ), + ); + }, + ), + ), + ], ), - ], - ), - ); - } else { - return const Center(child: Text("Some error occured")); - } - }), + ); + } else { + return const Center(child: Text("Some error occured")); + } + }), + ) ); } } + + + diff --git a/lib/programs screen/google_season_of_docs_screen.dart b/lib/programs screen/google_season_of_docs_screen.dart index bd01f0d..6e2df0e 100644 --- a/lib/programs screen/google_season_of_docs_screen.dart +++ b/lib/programs screen/google_season_of_docs_screen.dart @@ -1,5 +1,6 @@ import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:opso/modals/book_mark_model.dart'; @@ -9,12 +10,14 @@ import 'package:opso/widgets/gsod/gsod_project_widget_new.dart'; import 'package:opso/widgets/gsod/gsod_project_widget_old.dart'; import 'package:opso/widgets/year_button.dart'; + class GoogleSeasonOfDocsScreen extends StatefulWidget { @override State createState() => _GoogleSeasonOfDocsScreenState(); } + class _GoogleSeasonOfDocsScreenState extends State { String currentProgram = "Google Season of Docs"; bool isBookmarked = true; @@ -27,12 +30,14 @@ class _GoogleSeasonOfDocsScreenState extends State { bool flag = true; int selectedYear = 2023; + List projectList = []; Future? getProjectFunction; + Future initializeProjectLists() async { String response = - await rootBundle.loadString('assets/projects/gsod/gsod2023.json'); + await rootBundle.loadString('assets/projects/gsod/gsod2023.json'); var jsonList = await json.decode(response); for (var data in jsonList) { gsod2023.add(GsodModalNew.fromMap(data)); @@ -40,35 +45,39 @@ class _GoogleSeasonOfDocsScreenState extends State { print(gsod2023.length); projectList = List.from(gsod2023); response = - await rootBundle.loadString('assets/projects/gsod/gsod2022.json'); + await rootBundle.loadString('assets/projects/gsod/gsod2022.json'); jsonList = await json.decode(response); + for (var data in jsonList) { print(data["organization_name"]); gsod2022.add(GsodModalNew.fromMap(data)); } + response = - await rootBundle.loadString('assets/projects/gsod/gsod2021.json'); + await rootBundle.loadString('assets/projects/gsod/gsod2021.json'); jsonList = await json.decode(response); + for (var data in jsonList) { gsod2021.add(GsodModalNew.fromMap(data)); } response = - await rootBundle.loadString('assets/projects/gsod/gsod2020.json'); + await rootBundle.loadString('assets/projects/gsod/gsod2020.json'); jsonList = await json.decode(response); for (var data in jsonList) { gsod2020.add(GsodModalOld.fromMap(data)); } response = - await rootBundle.loadString('assets/projects/gsod/gsod2019.json'); + await rootBundle.loadString('assets/projects/gsod/gsod2019.json'); jsonList = await json.decode(response); for (var data in jsonList) { gsod2019.add(GsodModalOld.fromMap(data)); } } + @override void initState() { getProjectFunction = initializeProjectLists(); @@ -76,6 +85,7 @@ class _GoogleSeasonOfDocsScreenState extends State { super.initState(); } + Future _checkBookmarkStatus() async { bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProgram); setState(() { @@ -83,6 +93,7 @@ class _GoogleSeasonOfDocsScreenState extends State { }); } + void search(String searchText) { if (searchText.isEmpty) { switch (selectedYear) { @@ -109,320 +120,289 @@ class _GoogleSeasonOfDocsScreenState extends State { projectList = projectList .where( (element) => - element.organizationName - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.budget - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.acceptedProjectProposal - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.caseStudy - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.docsPage - .toLowerCase() - .contains(searchText.toLowerCase()), - ) + element.organizationName + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.budget + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.acceptedProjectProposal + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.caseStudy + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.docsPage + .toLowerCase() + .contains(searchText.toLowerCase()), + ) .toList(); } else { projectList = projectList .where( (element) => - element.organization - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.technicalWriter - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.mentor - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.project - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.originalProjectProposal - .toLowerCase() - .contains(searchText.toLowerCase()) || - element.report.toLowerCase().contains(searchText.toLowerCase()), - ) + element.organization + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.technicalWriter + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.mentor + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.project + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.originalProjectProposal + .toLowerCase() + .contains(searchText.toLowerCase()) || + element.report.toLowerCase().contains(searchText.toLowerCase()), + ) .toList(); } + setState(() {}); } - + Future _refresh() async { + // Fetch data for the next year based on the currently selected year + setState(() { + initializeProjectLists(); + selectedYear = 2023; + if (selectedYear > 2023) selectedYear = 2019; // Reset to the beginning if it exceeds 2023 + }); + } @override Widget build(BuildContext context) { var height = MediaQuery.sizeOf(context).height; var width = MediaQuery.sizeOf(context).width; - return Scaffold( - appBar: AppBar(title: const Text('OpSo'), actions: [ - IconButton( - icon: (isBookmarked) - ? const Icon(Icons.bookmark_add_rounded) - : const Icon(Icons.bookmark_add_outlined), - onPressed: () { - setState(() { - isBookmarked = !isBookmarked; - }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: - Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), - duration: - const Duration(seconds: 2), // Adjust the duration as needed - ), - ); - if (isBookmarked) { - print("Adding"); - HandleBookmark.addBookmark(currentProgram, currentPage); - } else { - print("Deleting"); - HandleBookmark.deleteBookmark(currentProgram); - } - }, - ) - ]), - body: FutureBuilder( - future: getProjectFunction, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.connectionState == ConnectionState.done) { - return Padding( - padding: - const EdgeInsets.symmetric(horizontal: 46, vertical: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - TextFormField( - decoration: InputDecoration( - filled: true, - // fillColor: const Color(0xFFEEEEEE), - hintText: 'Search', - suffixIcon: const Icon(Icons.search), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + appBar: AppBar(title: const Text('OpSo'), actions: [ + IconButton( + icon: (isBookmarked) + ? const Icon(Icons.bookmark_add_rounded) + : const Icon(Icons.bookmark_add_outlined), + onPressed: () { + setState(() { + isBookmarked = !isBookmarked; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: + Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), + duration: + const Duration(seconds: 2), // Adjust the duration as needed + ), + ); + if (isBookmarked) { + print("Adding"); + HandleBookmark.addBookmark(currentProgram, currentPage); + } else { + print("Deleting"); + HandleBookmark.deleteBookmark(currentProgram); + } + }, + ) + ]), + body: FutureBuilder( + future: getProjectFunction, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.connectionState == ConnectionState.done) { + return Padding( + padding: + const EdgeInsets.symmetric(horizontal: 46, vertical: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + TextFormField( + decoration: InputDecoration( + filled: true, + // fillColor: const Color(0xFFEEEEEE), + hintText: 'Search', + suffixIcon: const Icon(Icons.search), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - disabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), + contentPadding: const EdgeInsets.symmetric( + vertical: 12.0, horizontal: 20.0), ), - contentPadding: const EdgeInsets.symmetric( - vertical: 12.0, horizontal: 20.0), - ), - onFieldSubmitted: (value) { - print("value is $value"); - search(value.trim()); - }, - onChanged: (value) { - if (value.isEmpty) { - search(value); - } - }, - ), - const SizedBox(height: 20), - Container( - constraints: BoxConstraints( - maxHeight: height * 0.3, + onFieldSubmitted: (value) { + print("value is $value"); + search(value.trim()); + }, + onChanged: (value) { + if (value.isEmpty) { + search(value); + } + }, ), - width: width, - child: GridView( - physics: const NeverScrollableScrollPhysics(), - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - childAspectRatio: 1.5 / 0.6, - crossAxisSpacing: 15, - mainAxisSpacing: 15, + const SizedBox(height: 20), + Container( + constraints: BoxConstraints( + maxHeight: height * 0.3, ), - children: [ - YearButton( - year: "2019", - isEnabled: selectedYear == 2019 ? true : false, - onTap: () { - setState(() { - projectList = gsod2019; - selectedYear = 2019; - }); - }, - backgroundColor: selectedYear == 2019 - ? Colors.white - : const Color.fromRGBO(249, 171, 0, 1), - ), - YearButton( - year: "2020", - isEnabled: selectedYear == 2020 ? true : false, - onTap: () { - setState(() { - projectList = gsod2020; - selectedYear = 2020; - }); - }, - backgroundColor: selectedYear == 2020 - ? Colors.white - : const Color.fromRGBO(249, 171, 0, 1), - ), - YearButton( - year: "2021", - isEnabled: selectedYear == 2021 ? true : false, - onTap: () { - setState(() { - projectList = gsod2021; - selectedYear = 2021; - }); - }, - backgroundColor: selectedYear == 2021 - ? Colors.white - : const Color.fromRGBO(249, 171, 0, 1), + width: width, + child: GridView( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: 1.5 / 0.6, + crossAxisSpacing: 15, + mainAxisSpacing: 15, ), - YearButton( - year: "2022", - isEnabled: selectedYear == 2022 ? true : false, - onTap: () { - setState(() { - projectList = gsod2022; - selectedYear = 2022; - }); - }, - backgroundColor: selectedYear == 2022 - ? Colors.white - : const Color.fromRGBO(249, 171, 0, 1), - ), - YearButton( - year: "2023", - isEnabled: selectedYear == 2023 ? true : false, - onTap: () { - setState(() { - projectList = gsod2023; - selectedYear = 2023; - }); - }, - backgroundColor: selectedYear == 2023 - ? Colors.white - : const Color.fromRGBO(249, 171, 0, 1), - ), - ], + children: [ + YearButton( + year: "2019", + isEnabled: selectedYear == 2019 ? true : false, + onTap: () { + setState(() { + projectList = gsod2019; + selectedYear = 2019; + }); + }, + backgroundColor: selectedYear == 2019 + ? Colors.white + : const Color.fromRGBO(249, 171, 0, 1), + ), + YearButton( + year: "2020", + isEnabled: selectedYear == 2020 ? true : false, + onTap: () { + setState(() { + projectList = gsod2020; + selectedYear = 2020; + }); + }, + backgroundColor: selectedYear == 2020 + ? Colors.white + : const Color.fromRGBO(249, 171, 0, 1), + ), + YearButton( + year: "2021", + isEnabled: selectedYear == 2021 ? true : false, + onTap: () { + setState(() { + projectList = gsod2021; + selectedYear = 2021; + }); + }, + backgroundColor: selectedYear == 2021 + ? Colors.white + : const Color.fromRGBO(249, 171, 0, 1), + ), + YearButton( + year: "2022", + isEnabled: selectedYear == 2022 ? true : false, + onTap: () { + setState(() { + projectList = gsod2022; + selectedYear = 2022; + }); + }, + backgroundColor: selectedYear == 2022 + ? Colors.white + : const Color.fromRGBO(249, 171, 0, 1), + ), + YearButton( + year: "2023", + isEnabled: selectedYear == 2023 ? true : false, + onTap: () { + setState(() { + projectList = gsod2023; + selectedYear = 2023; + }); + }, + backgroundColor: selectedYear == 2023 + ? Colors.white + : const Color.fromRGBO(249, 171, 0, 1), + ), + ], + ), + ), + // const SizedBox(height: 20), + // SizedBox( + // height: 50, + // child: ElevatedButton( + // onPressed: () {}, + // style: ElevatedButton.styleFrom( + // shape: const RoundedRectangleBorder( + // borderRadius: BorderRadius.zero, + // ), + // backgroundColor: const Color.fromARGB( + // 255, 253, 214, 115), // Set button color + // padding: const EdgeInsets.symmetric( + // vertical: 10.0, horizontal: 20.0), + // ), + // child: const Text( + // 'View Projects', + // style: TextStyle(color: Colors.white, fontSize: 18), + // ), + // ), + // ), + const SizedBox( + height: 20, ), - ), - // const SizedBox(height: 20), - // SizedBox( - // height: 50, - // child: ElevatedButton( - // onPressed: () {}, - // style: ElevatedButton.styleFrom( - // shape: const RoundedRectangleBorder( - // borderRadius: BorderRadius.zero, - // ), - // backgroundColor: const Color.fromARGB( - // 255, 253, 214, 115), // Set button color - // padding: const EdgeInsets.symmetric( - // vertical: 10.0, horizontal: 20.0), - // ), - // child: const Text( - // 'View Projects', - // style: TextStyle(color: Colors.white, fontSize: 18), - // ), - // ), - // ), - const SizedBox( - height: 20, - ), - // Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - // children: [ - // Text( - // 'Filter by Language:', - // style: TextStyle(fontWeight: FontWeight.w400), - // ), - // Padding( - // padding: const EdgeInsets.all(8.0), - // child: Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - // children: [ - // DropdownWidget( - // items: languages, - // hintText: 'Language', - // onChanged: (newValue) { - // setState(() { - // switch (selectedYear) { - // case 2021: - // projectList = gsod2021; - // break; - // case 2022: - // projectList = gsod2022; - // break; - // case 2023: - // projectList = gsod2023; - // break; - // // case 2024: - // // projectList = gsod2024; - // // break; - // } - // searchTag(newValue); - // }); - // // Perform filtering based on selectedLanguage - // }, - // ), - // ], - // ), - // ) - // ], - // ), - Expanded( - // width: width, - child: ListView.builder( - itemCount: projectList.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 10), - child: selectedYear <= 2020 - ? GsodProjectWidgetOld( - index: index + 1, - modal: projectList[index], - height: height * 0.2, - width: width, - ) - : GsodProjectWidgetNew( - index: index + 1, - modal: projectList[index], - height: height * 0.2, - width: width, - ), - ); - }, + Expanded( + // width: width, + child: ListView.builder( + itemCount: projectList.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: selectedYear <= 2020 + ? GsodProjectWidgetOld( + index: index + 1, + modal: projectList[index], + height: height * 0.2, + width: width, + ) + : GsodProjectWidgetNew( + index: index + 1, + modal: projectList[index], + height: height * 0.2, + width: width, + ), + ); + }, + ), ), - ), - ], - ), - ); - } else { - return const Center(child: Text("Some error occured")); - } - }), + ], + ), + ); + } else { + return const Center(child: Text("Some error occured")); + } + }), + ), ); } } + diff --git a/lib/programs screen/google_summer_of_code_screen.dart b/lib/programs screen/google_summer_of_code_screen.dart index 706eef5..d324216 100644 --- a/lib/programs screen/google_summer_of_code_screen.dart +++ b/lib/programs screen/google_summer_of_code_screen.dart @@ -7,11 +7,13 @@ import '../services/ApiService.dart'; import '../widgets/SearchandFilterWidget.dart'; import '../widgets/year_button.dart'; + class GoogleSummerOfCodeScreen extends StatefulWidget { @override State createState() => _GoogleSummerOfCodeScreenState(); } + class _GoogleSummerOfCodeScreenState extends State { List gsoc2024 = []; List gsoc2023 = []; @@ -39,12 +41,14 @@ class _GoogleSummerOfCodeScreenState extends State { late Future _dataFetchFuture; final GlobalKey _listKey = GlobalKey(); + @override void initState() { super.initState(); _dataFetchFuture = getProjectData(); } + Future getProjectData() async { ApiService apiService = ApiService(); try { @@ -53,6 +57,7 @@ class _GoogleSummerOfCodeScreenState extends State { Gsoc orgData2023 = await apiService.getOrgByYear('2023'); Gsoc orgData2024 = await apiService.getOrgByYear('2024'); + setState(() { gsoc2021 = orgData2021.organizations ?? []; gsoc2022 = orgData2022.organizations ?? []; @@ -66,6 +71,7 @@ class _GoogleSummerOfCodeScreenState extends State { } } + void _clearAnimatedList() { for (var i = orgList.length - 1; i >= 0; i--) { _listKey.currentState?.removeItem( @@ -76,12 +82,14 @@ class _GoogleSummerOfCodeScreenState extends State { } } + void _populateAnimatedList(List organizations) { for (var i = 0; i < organizations.length; i++) { _listKey.currentState?.insertItem(i); } } + void searchTag(String searchTag) { setState(() { _clearAnimatedList(); @@ -92,6 +100,7 @@ class _GoogleSummerOfCodeScreenState extends State { }); } + void search(String searchText) { setState(() { _clearAnimatedList(); @@ -106,6 +115,7 @@ class _GoogleSummerOfCodeScreenState extends State { }); } + List _getOrganizationsByYear(int year) { switch (year) { case 2021: @@ -121,190 +131,204 @@ class _GoogleSummerOfCodeScreenState extends State { } } + + Future _refresh() async { + setState(() { + _dataFetchFuture = getProjectData(); + selectedYear = 2024; + }); + } + + @override Widget build(BuildContext context) { var height = MediaQuery.of(context).size.height; var width = MediaQuery.of(context).size.width; - return Scaffold( - appBar: AppBar( - title: Text('Google Summer of Code'), - ), - body: FutureBuilder( - future: _dataFetchFuture, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } else { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - TextFormField( - decoration: InputDecoration( - filled: true, - hintText: 'Search', - suffixIcon: const Icon(Icons.search), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + appBar: AppBar( + title: Text('Google Summer of Code'), + ), + body: FutureBuilder( + future: _dataFetchFuture, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + TextFormField( + decoration: InputDecoration( + filled: true, + hintText: 'Search', + suffixIcon: const Icon(Icons.search), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - disabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), + contentPadding: const EdgeInsets.symmetric( + vertical: 12.0, horizontal: 20.0), ), - contentPadding: const EdgeInsets.symmetric( - vertical: 12.0, horizontal: 20.0), + onFieldSubmitted: (value) { + search(value.trim()); + }, + onChanged: (value) { + if (value.isEmpty) { + search(value); + } + }, ), - onFieldSubmitted: (value) { - search(value.trim()); - }, - onChanged: (value) { - if (value.isEmpty) { - search(value); - } - }, - ), - const SizedBox(height: 20), - SizedBox( - height: height * 0.2, - width: width, - child: GridView( - physics: const NeverScrollableScrollPhysics(), - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - childAspectRatio: 1.5 / 0.6, - crossAxisSpacing: 15, - mainAxisSpacing: 15, + const SizedBox(height: 20), + SizedBox( + height: height * 0.2, + width: width, + child: GridView( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: 1.5 / 0.6, + crossAxisSpacing: 15, + mainAxisSpacing: 15, + ), + children: [ + YearButton( + year: "2021", + isEnabled: selectedYear == 2021, + onTap: () { + setState(() { + selectedYear = 2021; + _clearAnimatedList(); + orgList = gsoc2021; + }); + _populateAnimatedList(gsoc2021); + }, + backgroundColor: selectedYear == 2021 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2022", + isEnabled: selectedYear == 2022, + onTap: () { + setState(() { + selectedYear = 2022; + _clearAnimatedList(); + orgList = gsoc2022; + }); + _populateAnimatedList(gsoc2022); + }, + backgroundColor: selectedYear == 2022 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2023", + isEnabled: selectedYear == 2023, + onTap: () { + setState(() { + selectedYear = 2023; + _clearAnimatedList(); + orgList = gsoc2023; + }); + _populateAnimatedList(gsoc2023); + }, + backgroundColor: selectedYear == 2023 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + isEnabled: selectedYear == 2024, + year: "2024", + onTap: () { + setState(() { + selectedYear = 2024; + _clearAnimatedList(); + orgList = gsoc2024; + }); + _populateAnimatedList(gsoc2024); + }, + backgroundColor: selectedYear == 2024 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + ], ), + ), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - YearButton( - year: "2021", - isEnabled: selectedYear == 2021, - onTap: () { - setState(() { - selectedYear = 2021; - _clearAnimatedList(); - orgList = gsoc2021; - }); - _populateAnimatedList(gsoc2021); - }, - backgroundColor: selectedYear == 2021 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2022", - isEnabled: selectedYear == 2022, - onTap: () { - setState(() { - selectedYear = 2022; - _clearAnimatedList(); - orgList = gsoc2022; - }); - _populateAnimatedList(gsoc2022); - }, - backgroundColor: selectedYear == 2022 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2023", - isEnabled: selectedYear == 2023, - onTap: () { - setState(() { - selectedYear = 2023; - _clearAnimatedList(); - orgList = gsoc2023; - }); - _populateAnimatedList(gsoc2023); - }, - backgroundColor: selectedYear == 2023 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - isEnabled: selectedYear == 2024, - year: "2024", - onTap: () { - setState(() { - selectedYear = 2024; - _clearAnimatedList(); - orgList = gsoc2024; - }); - _populateAnimatedList(gsoc2024); - }, - backgroundColor: selectedYear == 2024 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), + const Text( + 'Filter by Language:', + style: TextStyle(fontWeight: FontWeight.w400), ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + DropdownWidget( + items: languages, + hintText: 'Language', + onChanged: (newValue) { + searchTag(newValue); + }, + ), + ], + ), + ) ], ), - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - const Text( - 'Filter by Language:', - style: TextStyle(fontWeight: FontWeight.w400), + Expanded( + child: AnimatedList( + key: _listKey, + initialItemCount: orgList.length, + itemBuilder: (context, index, animation) { + return _buildAnimatedItem(context, index, animation, height, width); + }, ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - DropdownWidget( - items: languages, - hintText: 'Language', - onChanged: (newValue) { - searchTag(newValue); - }, - ), - ], - ), - ) - ], - ), - Expanded( - child: AnimatedList( - key: _listKey, - initialItemCount: orgList.length, - itemBuilder: (context, index, animation) { - return _buildAnimatedItem(context, index, animation, height, width); - }, ), - ), - ], - ), - ); - } - }, + ], + ), + ); + } + }, + ), ), ); } + Widget _buildAnimatedItem(BuildContext context, int index, Animation animation, double height, double width) { return SizeTransition( sizeFactor: animation, @@ -340,8 +364,10 @@ class _GoogleSummerOfCodeScreenState extends State { } } + void main() { runApp(MaterialApp( home: GoogleSummerOfCodeScreen(), )); } + diff --git a/lib/programs screen/linux_foundation.dart b/lib/programs screen/linux_foundation.dart index df720d5..164fcc1 100644 --- a/lib/programs screen/linux_foundation.dart +++ b/lib/programs screen/linux_foundation.dart @@ -1,18 +1,22 @@ import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:opso/modals/book_mark_model.dart'; import 'package:opso/modals/linux_foundation_modal.dart'; import 'package:opso/widgets/linux_foundation_widget.dart'; + class LinuxFoundation extends StatefulWidget { const LinuxFoundation({super.key}); + @override State createState() => _LinuxFoundationState(); } + class _LinuxFoundationState extends State { bool isBookmarked = true; String currectPage = "/linux_foundation"; @@ -21,10 +25,12 @@ class _LinuxFoundationState extends State { List projectList = []; Future? getProjectListFunction; + Future initializeProjectLists() async { String response = await rootBundle .loadString('assets/projects/linux_foundation/linux_foundation.json'); + var jsonList = await json.decode(response); for (var data in jsonList) { modals.add(LinuxFoundationModal.fromMap(data)); @@ -33,6 +39,7 @@ class _LinuxFoundationState extends State { // setState(() {}); } + @override void initState() { super.initState(); @@ -40,6 +47,7 @@ class _LinuxFoundationState extends State { _checkBookmarkStatus(); } + Future _checkBookmarkStatus() async { bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProject); setState(() { @@ -47,6 +55,7 @@ class _LinuxFoundationState extends State { }); } + void search(String searchText) { if (searchText.isEmpty) { setState(() { @@ -56,121 +65,132 @@ class _LinuxFoundationState extends State { } projectList = projectList .where((LinuxFoundationModal element) => - element.name.toLowerCase().contains(searchText.toLowerCase())) + element.name.toLowerCase().contains(searchText.toLowerCase())) .toList(); setState(() {}); } + + Future _refresh() async { + await initializeProjectLists(); + setState(() {}); + } + + @override Widget build(BuildContext context) { var height = MediaQuery.sizeOf(context).height; var width = MediaQuery.sizeOf(context).width; - return Scaffold( - appBar: AppBar(title: const Text('OpSo'), actions: [ - IconButton( - icon: (isBookmarked) - ? const Icon(Icons.bookmark_add_rounded) - : const Icon(Icons.bookmark_add_outlined), - onPressed: () { - setState(() { - isBookmarked = !isBookmarked; - }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: - Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), - duration: - const Duration(seconds: 2), // Adjust the duration as needed - ), - ); - if (isBookmarked) { - print("Adding"); - HandleBookmark.addBookmark(currentProject, currectPage); - } else { - print("Deleting"); - HandleBookmark.deleteBookmark(currentProject); - } - }, - ) - ]), - body: FutureBuilder( - future: getProjectListFunction, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.connectionState == ConnectionState.done) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 16), - child: Column( - children: [ - TextFormField( - decoration: InputDecoration( - filled: true, - // fillColor: const Color(0xFFEEEEEE), - hintText: 'Search', - suffixIcon: const Icon(Icons.search), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + appBar: AppBar(title: const Text('OpSo'), actions: [ + IconButton( + icon: (isBookmarked) + ? const Icon(Icons.bookmark_add_rounded) + : const Icon(Icons.bookmark_add_outlined), + onPressed: () { + setState(() { + isBookmarked = !isBookmarked; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: + Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), + duration: + const Duration(seconds: 2), // Adjust the duration as needed + ), + ); + if (isBookmarked) { + print("Adding"); + HandleBookmark.addBookmark(currentProject, currectPage); + } else { + print("Deleting"); + HandleBookmark.deleteBookmark(currentProject); + } + }, + ) + ]), + body: FutureBuilder( + future: getProjectListFunction, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.connectionState == ConnectionState.done) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 16), + child: Column( + children: [ + TextFormField( + decoration: InputDecoration( + filled: true, + // fillColor: const Color(0xFFEEEEEE), + hintText: 'Search', + suffixIcon: const Icon(Icons.search), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - disabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), + contentPadding: const EdgeInsets.symmetric( + vertical: 12.0, horizontal: 20.0), ), - contentPadding: const EdgeInsets.symmetric( - vertical: 12.0, horizontal: 20.0), - ), - onFieldSubmitted: (value) { - print("value is $value"); - search(value.trim()); - }, - onChanged: (value) { - if (value.isEmpty) { - search(value); - } - }, - ), - const SizedBox(height: 20), - Expanded( - // width: width, - child: ListView.builder( - itemCount: projectList.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 10), - child: LinuxFoundationWidget( - // index: index + 1, - modal: projectList[index], - height: height * 0.2, - width: width, - ), - ); + onFieldSubmitted: (value) { + print("value is $value"); + search(value.trim()); + }, + onChanged: (value) { + if (value.isEmpty) { + search(value); + } }, ), - ), - ], - ), - ); - } - return Container(); - }, + const SizedBox(height: 20), + Expanded( + // width: width, + child: ListView.builder( + itemCount: projectList.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: LinuxFoundationWidget( + // index: index + 1, + modal: projectList[index], + height: height * 0.2, + width: width, + ), + ); + }, + ), + ), + ], + ), + ); + } + return Container(); + }, + ), ), ); } } + diff --git a/lib/programs screen/major_league_hacking_fellowship.dart b/lib/programs screen/major_league_hacking_fellowship.dart index 99ea70f..ccf3175 100644 --- a/lib/programs screen/major_league_hacking_fellowship.dart +++ b/lib/programs screen/major_league_hacking_fellowship.dart @@ -2,18 +2,23 @@ import 'package:flutter/material.dart'; import 'package:opso/modals/book_mark_model.dart'; + + class MajorLeagueHackingFellowship extends StatefulWidget { const MajorLeagueHackingFellowship({super.key}); + @override State createState() => _MajorLeagueHackingFellowshipState(); } + class _MajorLeagueHackingFellowshipState extends State { bool isBookmarked = true; String currectPage = "/major_league_hacking_fellowship"; String currentProject = "MajorLeagueHackingFellowship"; + @override void initState() { super.initState(); @@ -21,6 +26,8 @@ class _MajorLeagueHackingFellowshipState extends State _checkBookmarkStatus() async { bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProject); setState(() { @@ -28,43 +35,57 @@ class _MajorLeagueHackingFellowshipState extends State _refresh() async { + setState(() { + //implement refresh logic here when ready + }); + } + + @override Widget build(BuildContext context) { - return Scaffold( - - appBar: AppBar( - title: const Text('OpSo'), - actions: [ - IconButton( - icon: (isBookmarked) - ? const Icon(Icons.bookmark_add_rounded) - : const Icon(Icons.bookmark_add_outlined), - onPressed: () { - setState(() { - isBookmarked = !isBookmarked; - }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), - duration: const Duration(seconds: 2), // Adjust the duration as needed - ), - ); - if(isBookmarked){ - print("Adding"); - HandleBookmark.addBookmark(currentProject, currectPage); - } - else{ - print("Deleting"); - HandleBookmark.deleteBookmark(currentProject); - } - }, - ) - ] + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + + + appBar: AppBar( + title: const Text('OpSo'), + actions: [ + IconButton( + icon: (isBookmarked) + ? const Icon(Icons.bookmark_add_rounded) + : const Icon(Icons.bookmark_add_outlined), + onPressed: () { + setState(() { + isBookmarked = !isBookmarked; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), + duration: const Duration(seconds: 2), // Adjust the duration as needed + ), + ); + if(isBookmarked){ + print("Adding"); + HandleBookmark.addBookmark(currentProject, currectPage); + } + else{ + print("Deleting"); + HandleBookmark.deleteBookmark(currentProject); + } + }, + ) + ] ), - body: const Center( - child: Text('MajorLeagueHackingFellowship'), + + body: const Center( + child: Text('MajorLeagueHackingFellowship'), + ), ), ); } -} \ No newline at end of file +} + diff --git a/lib/programs screen/outreachy.dart b/lib/programs screen/outreachy.dart index 3bd3c54..ddc34e0 100644 --- a/lib/programs screen/outreachy.dart +++ b/lib/programs screen/outreachy.dart @@ -2,18 +2,23 @@ import 'package:flutter/material.dart'; import 'package:opso/modals/book_mark_model.dart'; + + class OutReachy extends StatefulWidget { const OutReachy({super.key}); + @override State createState() => _OutReachyState(); } + class _OutReachyState extends State { bool isBookmarked = true; String currectPage = "/outreachy"; String currentProject = "Outreachy"; + @override void initState() { super.initState(); @@ -21,50 +26,62 @@ class _OutReachyState extends State { } + + Future _checkBookmarkStatus() async { bool bookmarkStatus = await HandleBookmark.isBookmarked(currentProject); setState(() { isBookmarked = bookmarkStatus; }); } - + Future _refresh() async { + setState(() { + //implement refresh logic here when ready + }); + } @override Widget build(BuildContext context) { - return Scaffold( - - appBar: AppBar( - title: const Text('OpSo'), - actions: [ - IconButton( - icon: (isBookmarked) - ? const Icon(Icons.bookmark_add_rounded) - : const Icon(Icons.bookmark_add_outlined), - onPressed: () { - setState(() { - isBookmarked = !isBookmarked; - }); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), - duration: const Duration(seconds: 2), // Adjust the duration as needed - ), - ); - if(isBookmarked){ - print("Adding"); - HandleBookmark.addBookmark(currentProject, currectPage); - } - else{ - print("Deleting"); - HandleBookmark.deleteBookmark(currentProject); - } - }, - ) - ] + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + + + appBar: AppBar( + title: const Text('OpSo'), + actions: [ + IconButton( + icon: (isBookmarked) + ? const Icon(Icons.bookmark_add_rounded) + : const Icon(Icons.bookmark_add_outlined), + onPressed: () { + setState(() { + isBookmarked = !isBookmarked; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(isBookmarked ? 'Bookmark added' : 'Bookmark removed'), + duration: const Duration(seconds: 2), // Adjust the duration as needed + ), + ); + if(isBookmarked){ + print("Adding"); + HandleBookmark.addBookmark(currentProject, currectPage); + } + else{ + print("Deleting"); + HandleBookmark.deleteBookmark(currentProject); + } + }, + ) + ] ), - body: const Center( - child: Text('Outreachy'), + + body: const Center( + child: Text('Outreachy'), + ), ), ); } -} \ No newline at end of file +} + diff --git a/lib/programs screen/summer_of_bitcoin.dart b/lib/programs screen/summer_of_bitcoin.dart index f2b8f5d..304c7ac 100644 --- a/lib/programs screen/summer_of_bitcoin.dart +++ b/lib/programs screen/summer_of_bitcoin.dart @@ -1,29 +1,36 @@ import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:opso/modals/sob_project_modal.dart'; import 'package:opso/widgets/sob_project_widget.dart'; import 'package:opso/widgets/year_button.dart'; + import '../widgets/SearchandFilterWidget.dart'; + class SummerOfBitcoin extends StatefulWidget { const SummerOfBitcoin({super.key}); + @override State createState() => _SummerOfBitcoinState(); } + class _SummerOfBitcoinState extends State { List sob2023 = []; List sob2022 = []; List sob2021 = []; int selectedYear = 2023; + List projectList = []; Future? getProjectFunction; + Future initializeProjectLists() async { String response = await rootBundle.loadString('assets/projects/sob/sob2023.json'); @@ -33,6 +40,7 @@ class _SummerOfBitcoinState extends State { } projectList = sob2023; + response = await rootBundle.loadString('assets/projects/sob/sob2022.json'); jsonList = await json.decode(response); for (var data in jsonList) { @@ -45,12 +53,14 @@ class _SummerOfBitcoinState extends State { } } + @override void initState() { getProjectFunction = initializeProjectLists(); super.initState(); } + void searchTag(String searchTag) { projectList = projectList .where((SobProjectModal element) => @@ -59,6 +69,7 @@ class _SummerOfBitcoinState extends State { setState(() {}); } + void search(String searchText) { if (searchText.isEmpty) { switch (selectedYear) { @@ -102,193 +113,202 @@ class _SummerOfBitcoinState extends State { 'LND', 'Eclair' ]; - + Future _refresh() async { + setState(() { + initializeProjectLists(); + selectedYear = 2023; + }); + } @override Widget build(BuildContext context) { var height = MediaQuery.sizeOf(context).height; var width = MediaQuery.sizeOf(context).width; - return Scaffold( - appBar: AppBar( - title: const Text('Summer of Bitcoin'), - ), - body: FutureBuilder( - future: getProjectFunction, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.connectionState == ConnectionState.done) { - return Padding( - padding: - const EdgeInsets.symmetric(horizontal: 46, vertical: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - TextFormField( - decoration: InputDecoration( - filled: true, - hintText: 'Search', - suffixIcon: const Icon(Icons.search), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + return RefreshIndicator( + onRefresh: _refresh, + child: Scaffold( + appBar: AppBar( + title: const Text('Summer of Bitcoin'), + ), + body: FutureBuilder( + future: getProjectFunction, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.connectionState == ConnectionState.done) { + return Padding( + padding: + const EdgeInsets.symmetric(horizontal: 46, vertical: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + TextFormField( + decoration: InputDecoration( + filled: true, + hintText: 'Search', + suffixIcon: const Icon(Icons.search), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - disabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Color(0xFFEEEEEE), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: const BorderSide( + color: Color(0xFFEEEEEE), + ), ), + contentPadding: const EdgeInsets.symmetric( + vertical: 12.0, horizontal: 20.0), ), - contentPadding: const EdgeInsets.symmetric( - vertical: 12.0, horizontal: 20.0), + onFieldSubmitted: (value) { + search(value.trim()); + }, + onChanged: (value) { + if (value.isEmpty) { + search(value); + } + }, ), - onFieldSubmitted: (value) { - search(value.trim()); - }, - onChanged: (value) { - if (value.isEmpty) { - search(value); - } - }, - ), - const SizedBox(height: 20), - SizedBox( - height: height * 0.2, - width: width, - child: GridView( - physics: const NeverScrollableScrollPhysics(), - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - childAspectRatio: 1.5 / 0.6, - crossAxisSpacing: 15, - mainAxisSpacing: 15, + const SizedBox(height: 20), + SizedBox( + height: height * 0.2, + width: width, + child: GridView( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: 1.5 / 0.6, + crossAxisSpacing: 15, + mainAxisSpacing: 15, + ), + children: [ + YearButton( + year: "2021", + isEnabled: selectedYear == 2021 ? true : false, + onTap: () { + setState(() { + projectList = sob2021; + selectedYear = 2021; + }); + }, + backgroundColor: selectedYear == 2021 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2022", + isEnabled: selectedYear == 2022 ? true : false, + onTap: () { + setState(() { + projectList = sob2022; + selectedYear = 2022; + }); + }, + backgroundColor: selectedYear == 2022 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + YearButton( + year: "2023", + isEnabled: selectedYear == 2023 ? true : false, + onTap: () { + setState(() { + projectList = sob2023; + selectedYear = 2023; + }); + }, + backgroundColor: selectedYear == 2023 + ? Colors.white + : const Color.fromRGBO(255, 183, 77, 1), + ), + ], ), + ), + const SizedBox( + height: 20, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - YearButton( - year: "2021", - isEnabled: selectedYear == 2021 ? true : false, - onTap: () { - setState(() { - projectList = sob2021; - selectedYear = 2021; - }); - }, - backgroundColor: selectedYear == 2021 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2022", - isEnabled: selectedYear == 2022 ? true : false, - onTap: () { - setState(() { - projectList = sob2022; - selectedYear = 2022; - }); - }, - backgroundColor: selectedYear == 2022 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), - ), - YearButton( - year: "2023", - isEnabled: selectedYear == 2023 ? true : false, - onTap: () { - setState(() { - projectList = sob2023; - selectedYear = 2023; - }); - }, - backgroundColor: selectedYear == 2023 - ? Colors.white - : const Color.fromRGBO(255, 183, 77, 1), + const Text( + 'Filter by Org:', + style: TextStyle(fontWeight: FontWeight.w400), ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + DropdownWidget( + items: languages, + hintText: 'Org', + onChanged: (newValue) { + setState(() { + switch (selectedYear) { + case 2021: + projectList = sob2021; + break; + case 2022: + projectList = sob2022; + break; + case 2023: + projectList = sob2023; + break; + } + searchTag(newValue); + }); + // Perform filtering based on selectedLanguage + }, + ), + ], + ), + ) ], ), - ), - const SizedBox( - height: 20, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - const Text( - 'Filter by Org:', - style: TextStyle(fontWeight: FontWeight.w400), - ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - DropdownWidget( - items: languages, - hintText: 'Org', - onChanged: (newValue) { - setState(() { - switch (selectedYear) { - case 2021: - projectList = sob2021; - break; - case 2022: - projectList = sob2022; - break; - case 2023: - projectList = sob2023; - break; - } - searchTag(newValue); - }); - // Perform filtering based on selectedLanguage - }, + const SizedBox( + height: 20, + ), + Expanded( + // width: width, + child: ListView.builder( + itemCount: projectList.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: SobProjectWidget( + modal: projectList[index], + height: height * 0.2, + width: width, ), - ], - ), - ) - ], - ), - const SizedBox( - height: 20, - ), - Expanded( - // width: width, - child: ListView.builder( - itemCount: projectList.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 10), - child: SobProjectWidget( - modal: projectList[index], - height: height * 0.2, - width: width, - ), - ); - }, + ); + }, + ), ), - ), - ], - ), - ); - } else { - return const Center(child: Text("Some error occured")); - } - }), + ], + ), + ); + } else { + return const Center(child: Text("Some error occured")); + } + }), + ), ); } -} \ No newline at end of file +} +