'how can i make this gridview being returned from from a list of a futurebuilder searchable with a searchbar
how can i make this gridview being returned from from a list of a futurebuilder searchable with a searchbar, so i type youtube it shows youtube from the list
'this code returns a list of installed apps
uses Installed apps plugin
using a future builder, so i have 2 questions how can i add an if statement to make it not show an app and how can i add a search bar to this list
text to let me post
text to let me post
text to let me post'
text to let me post
text to let me post
text to let me post'
text to let me post
text to let me post
text to let me post'
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:installed_apps/app_info.dart';
import 'package:installed_apps/installed_apps.dart';
class InstalledAppsScreen extends StatelessWidget {
void Getapp() async {
var aplist = await InstalledApps.getInstalledApps(true, true);
}
@override
Widget build(BuildContext context) {
late var aplist;
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(100),
child: AppBar(
backgroundColor: Color(0xff707070),
centerTitle: true,
title: Text(
"APPS",
style: TextStyle(fontSize: 50),
),
)),
body: FutureBuilder<List<AppInfo>>(
future: InstalledApps.getInstalledApps(true, true),
builder:
(BuildContext buildContext, AsyncSnapshot<List<AppInfo>> snapshot) {
return snapshot.connectionState == ConnectionState.done
? snapshot.hasData
? Container(
margin: EdgeInsets.all(20),
child: GridView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
AppInfo app = snapshot.data![index];
aplist = snapshot.data!;
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(
color: Colors.black,
width: 4,
),
),
color: Colors.blueGrey,
child: GridTile(
child: InkWell(
onLongPress: () {
InstalledApps.openSettings(app.packageName!);
},
onTap: () {
InstalledApps.startApp(app.packageName!);
},
child: FittedBox(
fit: BoxFit.scaleDown,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
CircleAvatar(
child: Image.memory(
app.icon!,
),
radius: 30),
Container(
padding: EdgeInsets.all(1),
child: Center(
child: Text(
app.name!,
style: TextStyle(
fontSize: 30,
color: Colors.white),
),
),
)
],
),
),
),
),
),
);
},
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 300,
childAspectRatio: 3 / 2,
crossAxisSpacing: 20),
),
)
: Center(
child: Text(
"Error occurred while getting installed apps ...."))
: Center(child: Text("Getting installed apps ...."));
},
),
);
}
}
class Item {
/// App package name or Phone number
final String id;
final String name;
final Uint8List? icon;
const Item(this.id, this.name, this.icon);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
