Skip to content

Commit

Permalink
better pages with some error info
Browse files Browse the repository at this point in the history
  • Loading branch information
netharuM committed Apr 18, 2022
1 parent 3aae5e9 commit b75de0e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 23 deletions.
130 changes: 109 additions & 21 deletions lib/pages/statuses_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class StatusesPage extends StatefulWidget {
}

class _StatusesPageState extends State<StatusesPage> {
bool? isWhatsappInstalled;
bool? isPermissionGranted;
List<FileSystemEntity> _statusFiles = [];

Future<List<FileSystemEntity>> getFileList() async {
final bool permissionStatus =
await Permission.manageExternalStorage.isGranted;
if (!permissionStatus) {
await Permission.manageExternalStorage.request();
}
Directory dir = Directory(
'/storage/emulated/0/Android/media/com.whatsapp/Whatsapp/Media/.Statuses/');
List<FileSystemEntity> fileList = await dir.list(recursive: false).toList();
Expand All @@ -34,6 +31,23 @@ class _StatusesPageState extends State<StatusesPage> {
}

Future<void> _init() async {
isPermissionGranted = await Permission.manageExternalStorage.isGranted;
if (!isPermissionGranted!) {
await Permission.manageExternalStorage.request();
}

if (!await Directory(
'/storage/emulated/0/Android/media/com.whatsapp/Whatsapp/Media/.Statuses/')
.exists()) {
setState(() {
isWhatsappInstalled = false;
});
return;
}
setState(() {
isWhatsappInstalled = true;
});

List<FileSystemEntity> statusFiles = await getFileList();
setState(() {
_statusFiles = statusFiles;
Expand All @@ -42,24 +56,98 @@ class _StatusesPageState extends State<StatusesPage> {

@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
onRefresh: _init,
child: GridView.count(
crossAxisCount: 2,
children: [
for (int i = 0; i < _statusFiles.length; i++)
Padding(
padding: const EdgeInsets.all(8.0),
child: WhatsappStatusCard(
elevation: 10,
file: _statusFiles[i],
if (isWhatsappInstalled == null || isPermissionGranted == null) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (!isPermissionGranted!) {
return GestureDetector(
onTap: () async {
PermissionStatus permissionStatus =
await Permission.manageExternalStorage.request();
if (permissionStatus == PermissionStatus.granted) {
await _init();
}
},
child: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 64),
const Text(
'Permission denied',
style: TextStyle(fontSize: 32),
),
const Text(
'Please toggle that "Allow access to manage all files" to ON after clicking this',
textAlign: TextAlign.center,
),
Text(
'tap anywhere to give permission',
style: TextStyle(
color: Theme.of(context).primaryColor,
),
),
],
),
),
),
);
} else if (isWhatsappInstalled == false) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.error,
size: 200,
),
],
Text(
'Looks like whatsapp is not installed',
style: TextStyle(fontSize: 20),
),
Text('if you have whatsapp pls report this issue'),
Text('at Settings > About > Report a bug'),
],
),
),
);
} else {
return Scaffold(
body: RefreshIndicator(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
onRefresh: _init,
child: _statusFiles.isEmpty
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(
Icons.explore_rounded,
size: 200,
),
Center(
child: Text('Looks like there is nothing'),
),
],
)
: GridView.count(
crossAxisCount: 2,
children: [
for (int i = 0; i < _statusFiles.length; i++)
Padding(
padding: const EdgeInsets.all(8.0),
child: WhatsappStatusCard(
elevation: 10,
file: _statusFiles[i],
),
),
],
),
),
),
);
);
}
}
}
2 changes: 1 addition & 1 deletion lib/provider/theme_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ThemeProvider extends ChangeNotifier {
_init();
}

ThemeMode themeMode = ThemeMode.dark;
ThemeMode themeMode = ThemeMode.system;
late final SharedPreferences _prefs;

void _init() async {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.3+2
version: 1.0.3+3

environment:
sdk: ">=2.16.2 <3.0.0"
Expand Down

0 comments on commit b75de0e

Please sign in to comment.