add page for aur search
install aur package by button click
This commit is contained in:
		
							
								
								
									
										93
									
								
								frontend/lib/screens/aur_screen.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								frontend/lib/screens/aur_screen.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,93 @@
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
 | 
			
		||||
import 'package:aurcache/components/aur_search_table.dart';
 | 
			
		||||
import 'package:aurcache/models/aur_package.dart';
 | 
			
		||||
import 'package:aurcache/providers/aur_search_provider.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
import '../components/api/APIBuilder.dart';
 | 
			
		||||
import '../constants/color_constants.dart';
 | 
			
		||||
import '../providers/packages_provider.dart';
 | 
			
		||||
 | 
			
		||||
class AurScreen extends StatefulWidget {
 | 
			
		||||
  const AurScreen({super.key});
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  State<AurScreen> createState() => _AurScreenState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _AurScreenState extends State<AurScreen> {
 | 
			
		||||
  TextEditingController controller = TextEditingController();
 | 
			
		||||
  String query = "";
 | 
			
		||||
  Timer? timer;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(),
 | 
			
		||||
      body: MultiProvider(
 | 
			
		||||
        providers: [
 | 
			
		||||
          ChangeNotifierProvider(create: (_) => PackagesProvider()),
 | 
			
		||||
          ChangeNotifierProvider(create: (_) => AURSearchProvider())
 | 
			
		||||
        ],
 | 
			
		||||
        child: Padding(
 | 
			
		||||
          padding: const EdgeInsets.all(defaultPadding),
 | 
			
		||||
          child: Container(
 | 
			
		||||
            padding: const EdgeInsets.all(defaultPadding),
 | 
			
		||||
            decoration: const BoxDecoration(
 | 
			
		||||
              color: secondaryColor,
 | 
			
		||||
              borderRadius: BorderRadius.all(Radius.circular(10)),
 | 
			
		||||
            ),
 | 
			
		||||
            child: SingleChildScrollView(
 | 
			
		||||
              child: Column(
 | 
			
		||||
                crossAxisAlignment: CrossAxisAlignment.start,
 | 
			
		||||
                children: [
 | 
			
		||||
                  Text(
 | 
			
		||||
                    "AUR Packages",
 | 
			
		||||
                    style: Theme.of(context).textTheme.subtitle1,
 | 
			
		||||
                  ),
 | 
			
		||||
                  const Text("Search:"),
 | 
			
		||||
                  TextField(
 | 
			
		||||
                      controller: controller,
 | 
			
		||||
                      onChanged: (value) {
 | 
			
		||||
                        // cancel old timer if active
 | 
			
		||||
                        timer?.cancel();
 | 
			
		||||
                        // schedule new timer
 | 
			
		||||
                        timer = Timer(const Duration(milliseconds: 300), () {
 | 
			
		||||
                          setState(() {
 | 
			
		||||
                            query = value;
 | 
			
		||||
                          });
 | 
			
		||||
                        });
 | 
			
		||||
                      },
 | 
			
		||||
                      decoration:
 | 
			
		||||
                          const InputDecoration(hintText: "Type to search...")),
 | 
			
		||||
                  SizedBox(
 | 
			
		||||
                    width: double.infinity,
 | 
			
		||||
                    child: APIBuilder<AURSearchProvider, List<AurPackage>,
 | 
			
		||||
                            AurSearchDTO>(
 | 
			
		||||
                        dto: AurSearchDTO(query: query),
 | 
			
		||||
                        onLoad: () => Center(
 | 
			
		||||
                              child: Column(
 | 
			
		||||
                                children: [
 | 
			
		||||
                                  const SizedBox(
 | 
			
		||||
                                    height: 15,
 | 
			
		||||
                                  ),
 | 
			
		||||
                                  query.length < 3
 | 
			
		||||
                                      ? const Text(
 | 
			
		||||
                                          "Type to search for an AUR package")
 | 
			
		||||
                                      : const Text("loading")
 | 
			
		||||
                                ],
 | 
			
		||||
                              ),
 | 
			
		||||
                            ),
 | 
			
		||||
                        onData: (data) => AurSearchTable(data: data)),
 | 
			
		||||
                  )
 | 
			
		||||
                ],
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -61,23 +61,28 @@ class _PackageScreenState extends State<PackageScreen> {
 | 
			
		||||
                          child: ElevatedButton(
 | 
			
		||||
                            onPressed: () async {
 | 
			
		||||
                              final confirmResult =
 | 
			
		||||
                                  await showDeleteConfirmationDialog(context);
 | 
			
		||||
                              if (!confirmResult) return;
 | 
			
		||||
                                  await showConfirmationDialog(
 | 
			
		||||
                                context,
 | 
			
		||||
                                "Delete Package",
 | 
			
		||||
                                "Are you sure to delete this Package?",
 | 
			
		||||
                                () async {
 | 
			
		||||
                                  final succ = await API.deletePackage(pkg.id);
 | 
			
		||||
                                  if (succ) {
 | 
			
		||||
                                    context.pop();
 | 
			
		||||
 | 
			
		||||
                              final succ = await API.deletePackage(pkg.id);
 | 
			
		||||
                              if (succ) {
 | 
			
		||||
                                context.pop();
 | 
			
		||||
 | 
			
		||||
                                Provider.of<PackagesProvider>(context,
 | 
			
		||||
                                        listen: false)
 | 
			
		||||
                                    .refresh(context);
 | 
			
		||||
                                Provider.of<BuildsProvider>(context,
 | 
			
		||||
                                        listen: false)
 | 
			
		||||
                                    .refresh(context);
 | 
			
		||||
                                Provider.of<StatsProvider>(context,
 | 
			
		||||
                                        listen: false)
 | 
			
		||||
                                    .refresh(context);
 | 
			
		||||
                              }
 | 
			
		||||
                                    Provider.of<PackagesProvider>(context,
 | 
			
		||||
                                            listen: false)
 | 
			
		||||
                                        .refresh(context);
 | 
			
		||||
                                    Provider.of<BuildsProvider>(context,
 | 
			
		||||
                                            listen: false)
 | 
			
		||||
                                        .refresh(context);
 | 
			
		||||
                                    Provider.of<StatsProvider>(context,
 | 
			
		||||
                                            listen: false)
 | 
			
		||||
                                        .refresh(context);
 | 
			
		||||
                                  }
 | 
			
		||||
                                },
 | 
			
		||||
                                () {},
 | 
			
		||||
                              );
 | 
			
		||||
                            },
 | 
			
		||||
                            child: const Text(
 | 
			
		||||
                              "Delete",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user