search field redirect to aur page

This commit is contained in:
lukas-heiligenbrunner 2024-01-29 22:42:11 +01:00
parent c924a151cb
commit 0bb180f464
4 changed files with 23 additions and 19 deletions

View File

@ -1,5 +1,6 @@
import 'package:aurcache/components/dashboard/search_field.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart';
import '../../utils/responsive.dart';
@ -46,7 +47,9 @@ class Header extends StatelessWidget {
vertical: defaultPadding / (Responsive.isMobile(context) ? 2 : 1),
),
),
onPressed: () {},
onPressed: () {
context.push("/aur");
},
icon: const Icon(Icons.add),
label: const Text(
"Add New",

View File

@ -1,13 +1,7 @@
import 'package:aurcache/api/packages.dart';
import 'package:aurcache/providers/builds_provider.dart';
import 'package:aurcache/providers/stats_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import '../../api/API.dart';
import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart';
import '../../providers/packages_provider.dart';
class SearchField extends StatelessWidget {
SearchField({
@ -30,17 +24,11 @@ class SearchField extends StatelessWidget {
),
suffixIcon: InkWell(
onTap: () async {
// todo this is only temporary -> add this to a proper page
await API.addPackage(name: controller.text, force: true);
Provider.of<PackagesProvider>(context, listen: false)
.refresh(context);
Provider.of<BuildsProvider>(context, listen: false)
.refresh(context);
Provider.of<StatsProvider>(context, listen: false).refresh(context);
context.push("/aur?query=${controller.text}");
},
child: Container(
padding: EdgeInsets.all(defaultPadding * 0.75),
margin: EdgeInsets.symmetric(horizontal: defaultPadding / 2),
padding: const EdgeInsets.all(defaultPadding * 0.75),
margin: const EdgeInsets.symmetric(horizontal: defaultPadding / 2),
decoration: const BoxDecoration(
color: darkgreenColor,
borderRadius: BorderRadius.all(Radius.circular(10)),

View File

@ -43,7 +43,9 @@ final appRouter = GoRouter(
),
GoRoute(
path: '/aur',
builder: (context, state) => AurScreen(),
builder: (context, state) {
return AurScreen(initalQuery: state.uri.queryParameters["query"]);
},
),
GoRoute(
path: '/package/:id',

View File

@ -11,7 +11,9 @@ import '../constants/color_constants.dart';
import '../providers/packages_provider.dart';
class AurScreen extends StatefulWidget {
const AurScreen({super.key});
const AurScreen({super.key, this.initalQuery});
final String? initalQuery;
@override
State<AurScreen> createState() => _AurScreenState();
@ -22,6 +24,15 @@ class _AurScreenState extends State<AurScreen> {
String query = "";
Timer? timer;
@override
void initState() {
super.initState();
if (widget.initalQuery != null) {
query = widget.initalQuery!;
controller.text = widget.initalQuery!;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(