Skip to content

Commit

Permalink
bugfixed : apps update on pull refresh donw
Browse files Browse the repository at this point in the history
  • Loading branch information
jspw committed Nov 16, 2020
1 parent c6b841d commit 6301d4f
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 166 deletions.
Binary file added assets/images/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions lib/UI/Screens/apps.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import '../../Utility/libraries.dart';

class Apps extends StatefulWidget {
List<Application> apps;

Apps(this.apps);

@override
State<StatefulWidget> createState() {
// TODO: implement createState
// throw UnimplementedError();
return AppsState(apps);
}
}

class AppsState extends State {
List<Application> apps;
AppsState(this.apps);

Future<void> appInfo() async {
apps = await DeviceApps.getInstalledApplications(
includeAppIcons: true,
includeSystemApps: true,
onlyAppsWithLaunchIntent: true,
);

apps.sort(
(a, b) => a.appName.toLowerCase().compareTo(b.appName.toLowerCase()));

setState(() {
apps = apps;
});
print(apps);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
// arguments = ModalRoute.of(context).settings.arguments;
}

@override
Widget build(BuildContext context) {
// TODO: implement build
// throw UnimplementedError();
return Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.pink.withOpacity(0.5),
title: Text(
'Applications',
style: TextStyle(fontSize: 25),
),
titleSpacing: 1.2,
centerTitle: true,
leading: GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
// color: Colors.black,
child: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 35.0,
),
onPressed: null),
),
),
),
body: RefreshIndicator(
color: Colors.transparent,
onRefresh: () => appInfo(),
child: apps == null
? Center(child: Image.asset("assets/images/loader.gif"))
: GridView.count(
physics: BouncingScrollPhysics(),
crossAxisCount: 4,
children: List.generate(apps.length, (int i) {
Application app = apps[i];
return GestureDetector(
onTap: () => DeviceApps.openApp(app.packageName),
child: app is ApplicationWithIcon
? Card(
color: Colors.transparent,
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child: CircleAvatar(
backgroundImage: MemoryImage(
app.icon,
),
backgroundColor: Colors.white,
),
),
Text(
app.appName,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
],
),
),
)
: null);
}),
),
),
);
}
}
179 changes: 19 additions & 160 deletions lib/UI/Screens/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


import '../../Utility/libraries.dart';

class Home extends StatefulWidget {
Expand All @@ -24,29 +26,25 @@ class HomeState extends State {
}

_launchSms() async {
const url = "sms:";
if (await canLaunch(url)) {
await launch(url);
const uri = 'sms:';
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $url';
// iOS
const uri = 'sms:';
if (await canLaunch(uri)) {
await launch(uri);
} else {
throw 'Could not launch $uri';
}
}
}

void appInfo() async {
apps = await DeviceApps.getInstalledApplications(
includeAppIcons: true,
includeSystemApps: true,
onlyAppsWithLaunchIntent: true,
);

apps.sort(
(a, b) => a.appName.toLowerCase().compareTo(b.appName.toLowerCase()));

print(apps);
}

void appsRef() {
appInfo();
var data = await AppInformations.appInfo();
setState(() {
apps = data;
});
}

@override
Expand All @@ -70,134 +68,9 @@ class HomeState extends State {
height: 30.0,
),
GestureDetector(
onTap: () => showGeneralDialog(
barrierColor: Colors.black.withOpacity(0.5),
transitionBuilder: (context, a1, a2, widget) {
return Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: apps.length >= 1
? Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
title: Text('Applications'),
titleSpacing: 2.0,
centerTitle: true,
leading: GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
color: Colors.black,
child: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 35.0,
),
onPressed: null),
),
),
),
body: RefreshIndicator(
color: Colors.transparent,
onRefresh: () {
setState(() {
appInfo();
});
},
child: GridView.count(
physics: BouncingScrollPhysics(),
crossAxisCount: 4,
children: List.generate(apps.length, (int i) {
Application app = apps[i];
return GestureDetector(
// onDoubleTap: () => showGeneralDialog(
// context: context,
// pageBuilder:
// (context, anim1, anim2) {},
// barrierDismissible: true,
// barrierColor:
// Colors.black.withOpacity(0.4),
// barrierLabel: '',
// transitionBuilder: (context,
// anim1, anim2, child) {
// return Transform.rotate(
// angle: math.radians(
// anim1.value * 360),
// child: Opacity(
// opacity: anim1.value,
// child: AlertDialog(
// shape: OutlineInputBorder(
// borderRadius:
// BorderRadius
// .circular(
// 16.0)),
// title: Text(
// "Application Detail"),
// ),
// ),
// );
// },
// transitionDuration:
// Duration(milliseconds: 300),
// ),
onTap: () =>
DeviceApps.openApp(app.packageName),
child: GridTile(
child: app is ApplicationWithIcon
? Padding(
padding:
const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.center,
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: <Widget>[
Container(
// height: 45,
// width: 45,
child: CircleAvatar(
backgroundImage:
MemoryImage(
app.icon,
),
backgroundColor:
Colors.white,
),
),
Text(
app.appName,
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold,
),
overflow: TextOverflow
.ellipsis,
),
],
),
)
: null,
));
}),
),
),
)
: CircularProgressIndicator(),
),
);
},
transitionDuration: Duration(milliseconds: 300),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {},
),
onTap: () {
Navigator.of(context).push(RouteAnimator.createRoute(apps));
},
child: Container(
width: 35,
child: Image.asset(
Expand All @@ -220,20 +93,6 @@ class HomeState extends State {
color: Colors.white,
),
),
// buildIcons(
// () => print("Hello"),
// Icon(
// Icons.camera,
// color: Colors.white,
// ),
// ),
// buildIcons(
// () => print("Hello"),
// Icon(
// Icons.photo_album,
// color: Colors.white,
// ),
// ),
buildIcons(
() => AppSettings.openAppSettings(),
Icon(
Expand Down
Empty file added lib/UI/Screens/setting.dart
Empty file.
4 changes: 4 additions & 0 deletions lib/Utility/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ export 'package:flutter/material.dart';
export 'package:app_settings/app_settings.dart';
export 'package:url_launcher/url_launcher.dart';
export 'package:device_apps/device_apps.dart';
export 'package:system_setting/system_setting.dart';

//Custom

export '../UI/Screens/home.dart';
export 'routes.dart';
export '../UI/Screens/apps.dart';
export 'syncAppInformations.dart';
export 'routeAnimatior.dart';
23 changes: 23 additions & 0 deletions lib/Utility/routeAnimatior.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'libraries.dart';

class RouteAnimator {
static Route createRoute(List<Application> apps) {
{
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => Apps(apps),
transitionsBuilder: (context, a1, a2, widget) {
return Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: widget,
),
);
},
transitionDuration: Duration(milliseconds: 300),
barrierDismissible: true,
barrierLabel: '',
);
}
}
}
16 changes: 16 additions & 0 deletions lib/Utility/syncAppInformations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'libraries.dart';

class AppInformations {
static Future<List<Application>> appInfo() async {
var apps = await DeviceApps.getInstalledApplications(
includeAppIcons: true,
includeSystemApps: true,
onlyAppsWithLaunchIntent: true,
);

apps.sort(
(a, b) => a.appName.toLowerCase().compareTo(b.appName.toLowerCase()));

return apps;
}
}
Loading

0 comments on commit 6301d4f

Please sign in to comment.