From d3725db67edcfae5c8deaa8304312f052cd97705 Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sat, 1 Jul 2023 12:51:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 +++ lib/Widgets/search.dart | 73 +++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 4 ++- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 lib/Widgets/search.dart diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ea733fa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "activitypub" + ] +} \ No newline at end of file diff --git a/lib/Widgets/search.dart b/lib/Widgets/search.dart new file mode 100644 index 0000000..60eca80 --- /dev/null +++ b/lib/Widgets/search.dart @@ -0,0 +1,73 @@ +import 'package:activitypub/APIs/ActivityPubRelated/webfinger_api.dart'; +import 'package:flutter/material.dart'; + +class Search extends StatelessWidget { + Search({ + Key? key, + required this.appTitle, + required this.getProfile, + }) : super(key: key); + + final searchTextEditingController = TextEditingController(); + final String appTitle; + final Function(String profileId) getProfile; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + Form( + child: Row( + children: [ + Expanded( + child: TextFormField( + controller: searchTextEditingController, + decoration: const InputDecoration( + hintText: 'Search', + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return 'Please enter some text'; + } + return null; + }, + ), + ), + IconButton( + onPressed: () async { + String input = searchTextEditingController.text; + + if (input.contains("@")) { + WebfingerApi webfingerApi = WebfingerApi(); + String profileId = await webfingerApi.getUser(input); + + // ignore: use_build_context_synchronously + Navigator.push( + context, + PageRouteBuilder( + transitionDuration: const Duration(milliseconds: 300), + reverseTransitionDuration: + const Duration(milliseconds: 300), + pageBuilder: (context, animation, animation2) => + getProfile(profileId), + transitionsBuilder: + (context, animation, animation2, widget) => + SlideTransition( + position: Tween( + begin: const Offset(1.0, 0.0), + end: const Offset(0.0, 0.0), + ).animate(animation), + child: widget), + ), + ); + } + }, + icon: const Icon(Icons.search), + ), + ], + ), + ), + ], + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 7f6029f..a924214 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fedodo_general description: A flutter package which contains general components of the Fedodo-UIs. -version: 1.6.3 +version: 1.6.4 homepage: https://fedodo.org environment: @@ -10,6 +10,8 @@ environment: dependencies: flutter: sdk: flutter + activitypub: ^1.2.0 + shared_preferences: ^2.0.17 oauth2_client: ^3.0.0 flutter_guid: ^0.3.1