From a1c0b0bae6a41adf40901ff0e31ac831990651d4 Mon Sep 17 00:00:00 2001 From: Saumya-28 Date: Mon, 10 Jun 2024 23:36:06 +0530 Subject: [PATCH 1/3] conflict resolved --- .gradle/buildOutputCleanup/outputFiles.bin | Bin 0 -> 18695 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .gradle/buildOutputCleanup/outputFiles.bin diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000000000000000000000000000000000000..f05511fdcb973c9b9be53c9cbb10aeb644b8755b GIT binary patch literal 18695 zcmeI%!7Bt&9Ki864#LVxZDy|=91!I%P!4-?Sgj)$8>MIuT5(u~qWlNSNhz5vMY|=t zS9@ZUa+A1lkYW`n-t7E-ZE{me`cA!>*Z0jdZ$8%9%dxcn zKk%NtXxrJ^lk^+yhX*g&%i=@3^osUESEM_!Sida2sQqL-e!i05%}DpO- Date: Tue, 11 Jun 2024 00:05:07 +0530 Subject: [PATCH 2/3] chatbot implemented --- lib/ChatBotPage.dart | 143 +++++++++++++++++++++++++++++++++++++++++++ lib/home_page.dart | 82 ++++++++++++++++++++----- pubspec.lock | 32 ++++++---- pubspec.yaml | 1 + 4 files changed, 230 insertions(+), 28 deletions(-) create mode 100644 lib/ChatBotPage.dart diff --git a/lib/ChatBotPage.dart b/lib/ChatBotPage.dart new file mode 100644 index 0000000..f9f7187 --- /dev/null +++ b/lib/ChatBotPage.dart @@ -0,0 +1,143 @@ +import 'package:flutter/material.dart'; +import 'package:google_generative_ai/google_generative_ai.dart'; + + +const apiKey = 'Your Api Key'; + + +class ChatBotPage extends StatefulWidget { + const ChatBotPage({Key? key}) : super(key: key); + + + @override + _ChatBotPageState createState() => _ChatBotPageState(); +} + + +class _ChatBotPageState extends State { + final TextEditingController _controller = TextEditingController(); + final List> _messages = []; + GenerativeModel? _model; + + + @override + void initState() { + super.initState(); + _initializeModel(); + } + + + void _initializeModel() async { + _model = GenerativeModel( + model: 'gemini-1.5-flash-latest', + apiKey: apiKey, + ); + } + + + void _sendMessage() async { + if (_controller.text.isEmpty) return; + + + setState(() { + _messages.add({"sender": "user", "text": _controller.text}); + }); + + + final prompt = _controller.text; + _controller.clear(); + + + if (_model != null) { + final content = [Content.text(prompt)]; + final response = await _model!.generateContent(content); + setState(() { + _messages.add({"sender": "bot", "text": response.text!}); + }); + } + } + + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('ChatBot'), + ), + body: Column( + children: [ + Expanded( + child: ListView.builder( + itemCount: _messages.length, + itemBuilder: (context, index) { + final message = _messages[index]; + final isUser = message["sender"] == "user"; + return Align( + alignment: isUser ? Alignment.centerRight : Alignment.centerLeft, + child: Container( + constraints: BoxConstraints( + maxWidth: MediaQuery.of(context).size.width * 0.75, + ), + margin: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), + padding: const EdgeInsets.all(10.0), + decoration: BoxDecoration( + color: isUser ? Colors.blue[100] : Colors.grey[300], + borderRadius: BorderRadius.circular(10.0), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (!isUser) const CircleAvatar(child: Icon(Icons.android)), + if (!isUser) const SizedBox(width: 5.0), + Flexible( + child: Text(message["text"] ?? ''), + ), + if (isUser) const SizedBox(width: 5.0), + if (isUser) const CircleAvatar(child: Icon(Icons.person)), + ], + ), + ), + ); + }, + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + Expanded( + child: TextField( + controller: _controller, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: 'Enter your message', + ), + ), + ), + IconButton( + icon: const Icon(Icons.send), + onPressed: _sendMessage, + ), + ], + ), + ), + ], + ), + ); + } + + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } +} + + +void main() { + runApp(const MaterialApp( + home: ChatBotPage(), + )); +} + diff --git a/lib/home_page.dart b/lib/home_page.dart index e66aa4c..57fe0b7 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,8 +1,10 @@ import 'dart:ui'; import 'package:flutter_screenutil/flutter_screenutil.dart'; + import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:opso/ChatBotpage.dart'; import 'package:opso/opso_timeline.dart'; import 'package:opso/programs%20screen/girl_script.dart'; import 'package:opso/programs%20screen/google_season_of_docs_screen.dart'; @@ -18,15 +20,19 @@ import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:opso/widgets/faq.dart'; import 'dart:math' as math; + import 'about.dart'; + class HomePage extends StatefulWidget { const HomePage({super.key}); + @override State createState() => _HomePageState(); } + class _HomePageState extends State { @override void initState() { @@ -35,6 +41,7 @@ class _HomePageState extends State { _getInitialThemeMode(); } + int _initialLabelIndex = 0; void _getInitialThemeMode() async { final savedThemeMode = await AdaptiveTheme.getThemeMode(); @@ -49,6 +56,7 @@ class _HomePageState extends State { }); } + //show various notification from here void showNotification() async { await NotificationService.showNotification( @@ -57,6 +65,7 @@ class _HomePageState extends State { ); } + //used to show the notification every 5 ms void showScheduleNotification() async { await NotificationService.showNotification( @@ -66,6 +75,7 @@ class _HomePageState extends State { interval: 5); } + final List programs = [ Program( title: 'Google Summer of Code', @@ -101,6 +111,7 @@ class _HomePageState extends State { ), ]; + @override Widget build(BuildContext context) { // var media = MediaQuery.of(context).size; @@ -108,6 +119,7 @@ class _HomePageState extends State { ? Colors.black.withOpacity(0.6) // Example dark mode color : Colors.white.withOpacity(0.6); // Example light mode color + ScreenUtil.init( context, ); @@ -119,7 +131,7 @@ class _HomePageState extends State { title: Text( 'OpSo', style: - TextStyle(fontWeight: FontWeight.bold, fontSize: appBarFontSize), + TextStyle(fontWeight: FontWeight.bold, fontSize: appBarFontSize), ), actions: [ IconButton( @@ -129,14 +141,25 @@ class _HomePageState extends State { }, ), /*IconButton( - icon: Icon(Icons.menu), - onPressed: () { - // Open drawer when the menu icon is clicked - Scaffold.of(context).openDrawer(); - }, - ),*/ + icon: Icon(Icons.menu), + onPressed: () { + // Open drawer when the menu icon is clicked + Scaffold.of(context).openDrawer(); + }, + ),*/ ], ), + floatingActionButton: FloatingActionButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const ChatBotPage(), + ), + ); + }, + child: const Icon(Icons.chat_bubble_outline), + ), drawer: Drawer( backgroundColor: Colors.transparent, width: MediaQuery.of(context).size.width, @@ -154,7 +177,7 @@ class _HomePageState extends State { child: SafeArea( child: Padding( padding: - const EdgeInsets.only(left: 30, right: 30, top: 30), + const EdgeInsets.only(left: 30, right: 30, top: 30), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -219,7 +242,7 @@ class _HomePageState extends State { context, MaterialPageRoute( builder: (context) => - const BookMarkScreen())); + const BookMarkScreen())); }, ), const SizedBox(height: 15), @@ -236,7 +259,7 @@ class _HomePageState extends State { context, MaterialPageRoute( builder: (context) => - const OpsoTimeLineScreen(), + const OpsoTimeLineScreen(), ), ); }, @@ -259,7 +282,7 @@ class _HomePageState extends State { SizedBox(height: ScreenUtil().setHeight(15)), ListTile( leading: - const Icon(FontAwesomeIcons.circleInfo), + const Icon(FontAwesomeIcons.circleInfo), title: const Text('About'), onTap: () { Navigator.push( @@ -305,6 +328,7 @@ class _HomePageState extends State { ); } + void navigateToScreen(BuildContext context, Program program) { switch (program.title) { case 'Google Summer of Code': @@ -316,6 +340,7 @@ class _HomePageState extends State { ); break; + case 'Google Season of Docs': Navigator.push( context, @@ -325,6 +350,7 @@ class _HomePageState extends State { ); break; + case 'Major League Hacking Fellowship': Navigator.push( context, @@ -333,6 +359,7 @@ class _HomePageState extends State { ); break; + case 'GirlScript Summer of Code': Navigator.push( context, @@ -342,6 +369,7 @@ class _HomePageState extends State { ); break; + case 'Social Winter of Code': Navigator.push( context, @@ -351,13 +379,16 @@ class _HomePageState extends State { ); break; + case 'Outreachy': Navigator.push(context, MaterialPageRoute(builder: (context) => const OutReachy())); + case 'Summer of Bitcoin': Navigator.pushNamed(context, "/summer_of_bitcoin"); + case 'Summer of Bitcoin': Navigator.push( context, @@ -366,6 +397,7 @@ class _HomePageState extends State { ), ); + case 'Linux Foundation': Navigator.push(context, MaterialPageRoute(builder: (context) => const LinuxFoundation())); @@ -375,11 +407,13 @@ class _HomePageState extends State { } } + class ProgramOption extends StatelessWidget { final String title; final String imageAssetPath; final VoidCallback onTap; + const ProgramOption({ super.key, required this.title, @@ -387,6 +421,7 @@ class ProgramOption extends StatelessWidget { required this.onTap, }); + @override Widget build(BuildContext context) { final isDarkMode = Theme.of(context).brightness == Brightness.dark; @@ -433,6 +468,7 @@ class ProgramOption extends StatelessWidget { } } + class ProgramSearchDelegate extends SearchDelegate { final List programs = [ Program( @@ -469,6 +505,7 @@ class ProgramSearchDelegate extends SearchDelegate { ), ]; + @override List buildActions(BuildContext context) { return [ @@ -481,6 +518,7 @@ class ProgramSearchDelegate extends SearchDelegate { ]; } + @override Widget buildLeading(BuildContext context) { return IconButton( @@ -491,20 +529,23 @@ class ProgramSearchDelegate extends SearchDelegate { ); } + @override Widget buildResults(BuildContext context) { return Container(); } + @override Widget buildSuggestions(BuildContext context) { final List suggestionList = query.isEmpty ? [] : programs - .where((program) => - program.title.toLowerCase().contains(query.toLowerCase())) - .map((program) => program.title) - .toList(); + .where((program) => + program.title.toLowerCase().contains(query.toLowerCase())) + .map((program) => program.title) + .toList(); + return ListView.builder( itemCount: suggestionList.length, @@ -517,9 +558,10 @@ class ProgramSearchDelegate extends SearchDelegate { ); } + void navigateToScreen(BuildContext context, String title) { final Program selectedProgram = - programs.firstWhere((program) => program.title == title); + programs.firstWhere((program) => program.title == title); switch (selectedProgram.title) { case 'Google Summer of Code': Navigator.push( @@ -538,6 +580,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Major League Hacking Fellowship': Navigator.push( context, @@ -547,6 +590,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'GirlScript Summer of Code': Navigator.push( context, @@ -556,6 +600,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Social Winter of Code': Navigator.push( context, @@ -565,23 +610,28 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Linux Foundation': Navigator.push(context, MaterialPageRoute(builder: (context) => const LinuxFoundation())); break; + default: break; } } } + class Program { final String title; final String imageAssetPath; + Program({ required this.title, required this.imageAssetPath, }); } + diff --git a/pubspec.lock b/pubspec.lock index 0dda27a..befa82c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -208,6 +208,14 @@ packages: url: "https://pub.dev" source: hosted version: "10.7.0" + google_generative_ai: + dependency: "direct main" + description: + name: google_generative_ai + sha256: "76e35d93b8c1cd888f69a1a371f8c5dc54cec372b6c74a4c0a5d506e7cf82c1a" + url: "https://pub.dev" + source: hosted + version: "0.4.3" html: dependency: "direct main" description: @@ -260,26 +268,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.0" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "2.0.1" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "2.0.1" lints: dependency: transitive description: @@ -308,10 +316,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.11.0" multi_select_flutter: dependency: "direct main" description: @@ -489,10 +497,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" timeline_tile: dependency: "direct main" description: @@ -609,10 +617,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "13.0.0" web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7bbba2e..935277f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,6 +36,7 @@ dependencies: http: ^1.2.1 url_launcher: ^6.2.6 shared_preferences: ^2.0.11 + google_generative_ai: ^0.4.3 dio: ^5.4.3+1 animated_text_kit: ^4.2.2 adaptive_theme: ^3.6.0 From ffe44cc6f4ef25704799afa7253b575abe1804de Mon Sep 17 00:00:00 2001 From: Saumya-28 Date: Wed, 12 Jun 2024 14:07:55 +0530 Subject: [PATCH 3/3] chatbot added --- lib/ChatBotPage.dart | 19 +++++++--- lib/home_page.dart | 90 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 84 insertions(+), 25 deletions(-) diff --git a/lib/ChatBotPage.dart b/lib/ChatBotPage.dart index f9f7187..878ac73 100644 --- a/lib/ChatBotPage.dart +++ b/lib/ChatBotPage.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:google_generative_ai/google_generative_ai.dart'; -const apiKey = 'Your Api Key'; +const apiKey = 'put-gemini-api-key'; class ChatBotPage extends StatefulWidget { @@ -39,12 +39,14 @@ class _ChatBotPageState extends State { if (_controller.text.isEmpty) return; + + setState(() { - _messages.add({"sender": "user", "text": _controller.text}); + _messages.add({"sender": "user", "text": "${_controller.text}"}); }); - final prompt = _controller.text; + final prompt = _controller.text + "don't give answer in markdown format"; _controller.clear(); @@ -85,12 +87,17 @@ class _ChatBotPageState extends State { borderRadius: BorderRadius.circular(10.0), ), child: Row( - mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, children: [ if (!isUser) const CircleAvatar(child: Icon(Icons.android)), if (!isUser) const SizedBox(width: 5.0), - Flexible( - child: Text(message["text"] ?? ''), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(message["text"] ?? ''), + ], + ), ), if (isUser) const SizedBox(width: 5.0), if (isUser) const CircleAvatar(child: Icon(Icons.person)), diff --git a/lib/home_page.dart b/lib/home_page.dart index 4924df6..57fe0b7 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,7 +1,10 @@ import 'dart:ui'; import 'package:flutter_screenutil/flutter_screenutil.dart'; + + import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:opso/ChatBotpage.dart'; import 'package:opso/opso_timeline.dart'; import 'package:opso/programs%20screen/girl_script.dart'; import 'package:opso/programs%20screen/google_season_of_docs_screen.dart'; @@ -16,24 +19,29 @@ import 'package:opso/widgets/book_mark_screen.dart'; import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:opso/widgets/faq.dart'; import 'dart:math' as math; -import 'package:awesome_notifications/awesome_notifications.dart'; + + import 'about.dart'; + class HomePage extends StatefulWidget { const HomePage({super.key}); + @override State createState() => _HomePageState(); } + class _HomePageState extends State { @override void initState() { - // showNotification(); + showNotification(); super.initState(); _getInitialThemeMode(); } + int _initialLabelIndex = 0; void _getInitialThemeMode() async { final savedThemeMode = await AdaptiveTheme.getThemeMode(); @@ -48,6 +56,7 @@ class _HomePageState extends State { }); } + //show various notification from here void showNotification() async { await NotificationService.showNotification( @@ -56,6 +65,7 @@ class _HomePageState extends State { ); } + //used to show the notification every 5 ms void showScheduleNotification() async { await NotificationService.showNotification( @@ -65,6 +75,7 @@ class _HomePageState extends State { interval: 5); } + final List programs = [ Program( title: 'Google Summer of Code', @@ -100,6 +111,7 @@ class _HomePageState extends State { ), ]; + @override Widget build(BuildContext context) { // var media = MediaQuery.of(context).size; @@ -107,6 +119,7 @@ class _HomePageState extends State { ? Colors.black.withOpacity(0.6) // Example dark mode color : Colors.white.withOpacity(0.6); // Example light mode color + ScreenUtil.init( context, ); @@ -118,7 +131,7 @@ class _HomePageState extends State { title: Text( 'OpSo', style: - TextStyle(fontWeight: FontWeight.bold, fontSize: appBarFontSize), + TextStyle(fontWeight: FontWeight.bold, fontSize: appBarFontSize), ), actions: [ IconButton( @@ -128,14 +141,25 @@ class _HomePageState extends State { }, ), /*IconButton( - icon: Icon(Icons.menu), - onPressed: () { - // Open drawer when the menu icon is clicked - Scaffold.of(context).openDrawer(); - }, - ),*/ + icon: Icon(Icons.menu), + onPressed: () { + // Open drawer when the menu icon is clicked + Scaffold.of(context).openDrawer(); + }, + ),*/ ], ), + floatingActionButton: FloatingActionButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const ChatBotPage(), + ), + ); + }, + child: const Icon(Icons.chat_bubble_outline), + ), drawer: Drawer( backgroundColor: Colors.transparent, width: MediaQuery.of(context).size.width, @@ -153,7 +177,7 @@ class _HomePageState extends State { child: SafeArea( child: Padding( padding: - const EdgeInsets.only(left: 30, right: 30, top: 30), + const EdgeInsets.only(left: 30, right: 30, top: 30), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -218,7 +242,7 @@ class _HomePageState extends State { context, MaterialPageRoute( builder: (context) => - const BookMarkScreen())); + const BookMarkScreen())); }, ), const SizedBox(height: 15), @@ -235,7 +259,7 @@ class _HomePageState extends State { context, MaterialPageRoute( builder: (context) => - const OpsoTimeLineScreen(), + const OpsoTimeLineScreen(), ), ); }, @@ -249,7 +273,8 @@ class _HomePageState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => FAQPage(), + builder: (context) => + FAQPage(), ), ); }, @@ -257,7 +282,7 @@ class _HomePageState extends State { SizedBox(height: ScreenUtil().setHeight(15)), ListTile( leading: - const Icon(FontAwesomeIcons.circleInfo), + const Icon(FontAwesomeIcons.circleInfo), title: const Text('About'), onTap: () { Navigator.push( @@ -303,6 +328,7 @@ class _HomePageState extends State { ); } + void navigateToScreen(BuildContext context, Program program) { switch (program.title) { case 'Google Summer of Code': @@ -314,6 +340,7 @@ class _HomePageState extends State { ); break; + case 'Google Season of Docs': Navigator.push( context, @@ -323,6 +350,7 @@ class _HomePageState extends State { ); break; + case 'Major League Hacking Fellowship': Navigator.push( context, @@ -331,6 +359,7 @@ class _HomePageState extends State { ); break; + case 'GirlScript Summer of Code': Navigator.push( context, @@ -340,6 +369,7 @@ class _HomePageState extends State { ); break; + case 'Social Winter of Code': Navigator.push( context, @@ -349,13 +379,16 @@ class _HomePageState extends State { ); break; + case 'Outreachy': Navigator.push(context, MaterialPageRoute(builder: (context) => const OutReachy())); + case 'Summer of Bitcoin': Navigator.pushNamed(context, "/summer_of_bitcoin"); + case 'Summer of Bitcoin': Navigator.push( context, @@ -364,6 +397,7 @@ class _HomePageState extends State { ), ); + case 'Linux Foundation': Navigator.push(context, MaterialPageRoute(builder: (context) => const LinuxFoundation())); @@ -373,11 +407,13 @@ class _HomePageState extends State { } } + class ProgramOption extends StatelessWidget { final String title; final String imageAssetPath; final VoidCallback onTap; + const ProgramOption({ super.key, required this.title, @@ -385,6 +421,7 @@ class ProgramOption extends StatelessWidget { required this.onTap, }); + @override Widget build(BuildContext context) { final isDarkMode = Theme.of(context).brightness == Brightness.dark; @@ -431,6 +468,7 @@ class ProgramOption extends StatelessWidget { } } + class ProgramSearchDelegate extends SearchDelegate { final List programs = [ Program( @@ -467,6 +505,7 @@ class ProgramSearchDelegate extends SearchDelegate { ), ]; + @override List buildActions(BuildContext context) { return [ @@ -479,6 +518,7 @@ class ProgramSearchDelegate extends SearchDelegate { ]; } + @override Widget buildLeading(BuildContext context) { return IconButton( @@ -489,20 +529,23 @@ class ProgramSearchDelegate extends SearchDelegate { ); } + @override Widget buildResults(BuildContext context) { return Container(); } + @override Widget buildSuggestions(BuildContext context) { final List suggestionList = query.isEmpty ? [] : programs - .where((program) => - program.title.toLowerCase().contains(query.toLowerCase())) - .map((program) => program.title) - .toList(); + .where((program) => + program.title.toLowerCase().contains(query.toLowerCase())) + .map((program) => program.title) + .toList(); + return ListView.builder( itemCount: suggestionList.length, @@ -515,9 +558,10 @@ class ProgramSearchDelegate extends SearchDelegate { ); } + void navigateToScreen(BuildContext context, String title) { final Program selectedProgram = - programs.firstWhere((program) => program.title == title); + programs.firstWhere((program) => program.title == title); switch (selectedProgram.title) { case 'Google Summer of Code': Navigator.push( @@ -536,6 +580,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Major League Hacking Fellowship': Navigator.push( context, @@ -545,6 +590,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'GirlScript Summer of Code': Navigator.push( context, @@ -554,6 +600,7 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Social Winter of Code': Navigator.push( context, @@ -563,23 +610,28 @@ class ProgramSearchDelegate extends SearchDelegate { ); break; + case 'Linux Foundation': Navigator.push(context, MaterialPageRoute(builder: (context) => const LinuxFoundation())); break; + default: break; } } } + class Program { final String title; final String imageAssetPath; + Program({ required this.title, required this.imageAssetPath, }); } +