From 001d42e14adcab5c5161fe1571ad42480147621e Mon Sep 17 00:00:00 2001 From: Aegeontis <140899260+Aegeontis@users.noreply.github.com> Date: Sat, 19 Oct 2024 00:10:27 +0200 Subject: [PATCH] Go back to start screen from results --- lib/screens/result.dart | 391 +++++++++++++++++++++------------------- 1 file changed, 201 insertions(+), 190 deletions(-) diff --git a/lib/screens/result.dart b/lib/screens/result.dart index 16e9b5a..2efafef 100644 --- a/lib/screens/result.dart +++ b/lib/screens/result.dart @@ -45,133 +45,104 @@ class _ResultScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - iconTheme: - IconThemeData(color: Theme.of(context).colorScheme.primary), - title: Center( - // Capitalize the first letter of the query - child: Text( - widget.query[0].toUpperCase() + widget.query.substring(1), - style: Theme.of(context).textTheme.headlineLarge)), - ), - body: SafeArea( - // show 3 pictures from the ebay picture map - child: Padding( - padding: EdgeInsets.all(15), - child: Column(mainAxisSize: MainAxisSize.min, children: [ - displayedImages == null - ? Text("No images found") - : Text("Images from ebay", - style: Theme.of(context).textTheme.headlineMedium), - const SizedBox(height: 10), - displayedImages != null - ? Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Theme.of(context).colorScheme.secondary, - ), - child: Padding( - padding: EdgeInsets.all(10), - child: GridView.builder( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 3, - crossAxisSpacing: 10, - mainAxisSpacing: 10, - ), - itemCount: displayedImages!.length, - itemBuilder: (context, index) { - return ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Image.network(displayedImages![index], - fit: BoxFit.cover), - ); - }, - ))) - : const SizedBox(), - Padding( - padding: EdgeInsets.all(10), - child: Row(children: [ - TextButton( - style: TextButton.styleFrom( - foregroundColor: - Theme.of(context).colorScheme.onPrimary, - backgroundColor: - Theme.of(context).colorScheme.primary, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - )), - onPressed: () { - downloadImages(widget.query, displayedImages!); - }, - child: Padding( - padding: EdgeInsets.all(7), - child: Text("Download images", - style: Theme.of(context) - .textTheme - .titleLarge! - .copyWith( - color: Theme.of(context) - .colorScheme - .onPrimary, - fontWeight: FontWeight.bold)), - ), - ), - const Spacer(), - TextButton( - style: TextButton.styleFrom( - foregroundColor: - Theme.of(context).colorScheme.onPrimary, - backgroundColor: - Theme.of(context).colorScheme.primary, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - )), - onPressed: () { - checkImages(displayedImages!); - }, - child: Padding( - padding: EdgeInsets.all(7), - child: Text("Check images", - style: Theme.of(context) - .textTheme - .titleLarge! - .copyWith( - color: Theme.of(context) - .colorScheme - .onPrimary, - fontWeight: FontWeight.bold)), - ), - ), - const Spacer(), - TextButton( - style: TextButton.styleFrom( - foregroundColor: - Theme.of(context).colorScheme.onPrimary, - backgroundColor: - Theme.of(context).colorScheme.primary, - shape: RoundedRectangleBorder( + return WillPopScope( + onWillPop: () async { + // Go back to start screen + Navigator.of(context).popUntil((route) => route.isFirst); + return false; + }, + child: Scaffold( + appBar: AppBar( + iconTheme: + IconThemeData(color: Theme.of(context).colorScheme.primary), + title: Center( + // Capitalize the first letter of the query + child: Text( + widget.query[0].toUpperCase() + widget.query.substring(1), + style: Theme.of(context).textTheme.headlineLarge)), + ), + body: SafeArea( + // show 3 pictures from the ebay picture map + child: Padding( + padding: EdgeInsets.all(15), + child: Column(mainAxisSize: MainAxisSize.min, children: [ + displayedImages == null + ? Text("No images found") + : Text("Images from ebay", + style: Theme.of(context).textTheme.headlineMedium), + const SizedBox(height: 10), + displayedImages != null + ? Container( + decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), - )), - onPressed: () async { - displayedImages = await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => SelectPicturesScreen( - imageMap: widget.imageMap!, - searchQuery: widget.query, - ), + color: Theme.of(context).colorScheme.secondary, + ), + child: Padding( + padding: EdgeInsets.all(10), + child: GridView.builder( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + gridDelegate: + SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 3, + crossAxisSpacing: 10, + mainAxisSpacing: 10, + ), + itemCount: displayedImages!.length, + itemBuilder: (context, index) { + return ClipRRect( + borderRadius: BorderRadius.circular(10), + child: Image.network( + displayedImages![index], + fit: BoxFit.cover), + ); + }, + ))) + : const SizedBox(), + Padding( + padding: EdgeInsets.all(10), + child: Row(children: [ + TextButton( + style: TextButton.styleFrom( + foregroundColor: + Theme.of(context).colorScheme.onPrimary, + backgroundColor: + Theme.of(context).colorScheme.primary, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + )), + onPressed: () { + downloadImages(widget.query, displayedImages!); + }, + child: Padding( + padding: EdgeInsets.all(7), + child: Text("Download images", + style: Theme.of(context) + .textTheme + .titleLarge! + .copyWith( + color: Theme.of(context) + .colorScheme + .onPrimary, + fontWeight: FontWeight.bold)), ), - ); - setState(() {}); - }, - child: Padding( - padding: EdgeInsets.all(7), - child: Row(children: [ - Text("Select different images", + ), + const Spacer(), + TextButton( + style: TextButton.styleFrom( + foregroundColor: + Theme.of(context).colorScheme.onPrimary, + backgroundColor: + Theme.of(context).colorScheme.primary, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + )), + onPressed: () { + checkImages(displayedImages!); + }, + child: Padding( + padding: EdgeInsets.all(7), + child: Text("Check images", style: Theme.of(context) .textTheme .titleLarge! @@ -180,72 +151,112 @@ class _ResultScreenState extends State { .colorScheme .onPrimary, fontWeight: FontWeight.bold)), - const SizedBox(width: 5), - Icon(Icons.arrow_forward, - color: - Theme.of(context).colorScheme.onPrimary, - size: 35) - ])), - ) - ])), - const SizedBox(height: 30), - Padding( - padding: EdgeInsets.all(10), - child: Text("LLM response", - style: Theme.of(context).textTheme.headlineMedium), - ), - Row(children: [ - const Spacer(), - IconButton( - onPressed: () async { - setState(() { - loadingLLMQuery = true; - }); - widget.llmResponse = await queryLLM( - await getLLMSettings(), - widget.reviews, - widget.query); - setState(() { - loadingLLMQuery = false; - }); - }, - icon: Icon(Icons.refresh, size: 30)), - IconButton( - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const LLMSettingsScreen())), - icon: Icon(Icons.settings, size: 30)), - // TODO: Add copy implementation - IconButton( - onPressed: () => Clipboard.setData( - ClipboardData(text: widget.llmResponse ?? "")), - icon: Icon(Icons.copy, size: 30)), - ]), - !loadingLLMQuery - ? Expanded( - child: TextFormField( - readOnly: true, - maxLines: null, - expands: true, - style: TextStyle( - color: Theme.of(context).colorScheme.onSecondary, - fontWeight: FontWeight.bold), - // Set text color to red - textAlignVertical: TextAlignVertical.top, - initialValue: widget.llmResponse, - decoration: InputDecoration( - filled: true, - fillColor: Theme.of(context).colorScheme.secondary, - border: const OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(10), ), ), - ), - )) - : const CircularProgressIndicator() - ])), - )); + const Spacer(), + TextButton( + style: TextButton.styleFrom( + foregroundColor: + Theme.of(context).colorScheme.onPrimary, + backgroundColor: + Theme.of(context).colorScheme.primary, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + )), + onPressed: () async { + displayedImages = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => SelectPicturesScreen( + imageMap: widget.imageMap!, + searchQuery: widget.query, + ), + ), + ); + setState(() {}); + }, + child: Padding( + padding: EdgeInsets.all(7), + child: Row(children: [ + Text("Select different images", + style: Theme.of(context) + .textTheme + .titleLarge! + .copyWith( + color: Theme.of(context) + .colorScheme + .onPrimary, + fontWeight: FontWeight.bold)), + const SizedBox(width: 5), + Icon(Icons.arrow_forward, + color: Theme.of(context) + .colorScheme + .onPrimary, + size: 35) + ])), + ) + ])), + const SizedBox(height: 30), + Padding( + padding: EdgeInsets.all(10), + child: Text("LLM response", + style: Theme.of(context).textTheme.headlineMedium), + ), + Row(children: [ + const Spacer(), + IconButton( + onPressed: () async { + setState(() { + loadingLLMQuery = true; + }); + widget.llmResponse = await queryLLM( + await getLLMSettings(), + widget.reviews, + widget.query); + setState(() { + loadingLLMQuery = false; + }); + }, + icon: Icon(Icons.refresh, size: 30)), + IconButton( + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + const LLMSettingsScreen())), + icon: Icon(Icons.settings, size: 30)), + // TODO: Add copy implementation + IconButton( + onPressed: () => Clipboard.setData( + ClipboardData(text: widget.llmResponse ?? "")), + icon: Icon(Icons.copy, size: 30)), + ]), + !loadingLLMQuery + ? Expanded( + child: TextFormField( + readOnly: true, + maxLines: null, + expands: true, + style: TextStyle( + color: + Theme.of(context).colorScheme.onSecondary, + fontWeight: FontWeight.bold), + // Set text color to red + textAlignVertical: TextAlignVertical.top, + initialValue: widget.llmResponse, + decoration: InputDecoration( + filled: true, + fillColor: + Theme.of(context).colorScheme.secondary, + border: const OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(10), + ), + ), + ), + )) + : const CircularProgressIndicator() + ])), + ))); } }