Skip to content

Commit

Permalink
added comments to the code
Browse files Browse the repository at this point in the history
just to help devs
and also changed appName to Whatskit Flutter Demo i didnt even notice the change
  • Loading branch information
netharuM committed Apr 19, 2022
1 parent aba1169 commit 8697af9
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 44 deletions.
24 changes: 5 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import 'package:whatskit/provider/theme_provider.dart';
import 'package:provider/provider.dart';

void main() {
runApp(const MyApp());
runApp(const Application());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// main app
class Application extends StatelessWidget {
const Application({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -19,7 +20,7 @@ class MyApp extends StatelessWidget {
builder: (context, _) {
final ThemeProvider themeProvider = Provider.of<ThemeProvider>(context);
return MaterialApp(
title: 'Flutter Demo',
title: 'Whatskit',
themeMode: themeProvider.getThemeMode,
theme: AppThemes.lightTheme,
darkTheme: AppThemes.darkTheme,
Expand Down Expand Up @@ -89,18 +90,3 @@ class _AppState extends State<App> {
);
}
}

MaterialColor generateMaterialColorFromColor(Color color) {
return MaterialColor(color.value, {
50: Color.fromRGBO(color.red, color.green, color.blue, 0.1),
100: Color.fromRGBO(color.red, color.green, color.blue, 0.2),
200: Color.fromRGBO(color.red, color.green, color.blue, 0.3),
300: Color.fromRGBO(color.red, color.green, color.blue, 0.4),
400: Color.fromRGBO(color.red, color.green, color.blue, 0.5),
500: Color.fromRGBO(color.red, color.green, color.blue, 0.6),
600: Color.fromRGBO(color.red, color.green, color.blue, 0.7),
700: Color.fromRGBO(color.red, color.green, color.blue, 0.8),
800: Color.fromRGBO(color.red, color.green, color.blue, 0.9),
900: Color.fromRGBO(color.red, color.green, color.blue, 1.0),
});
}
5 changes: 5 additions & 0 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:whatskit/provider/theme_provider.dart';

/// settings page of the app
class SettingsPage extends StatefulWidget {
const SettingsPage({Key? key}) : super(key: key);

Expand Down Expand Up @@ -64,6 +65,7 @@ class _SettingsPageState extends State<SettingsPage> {
iconColor: Colors.pink,
icon: Icons.cleaning_services_rounded,
onTap: () async {
// clearing the rendered cache if the user forgot to clear the saved cache
var renderedCacheDir = Directory(
'/storage/emulated/0/Android/data/com.netharuM.whatskit/files/Trimmer');
if (await renderedCacheDir.exists()) {
Expand Down Expand Up @@ -114,6 +116,7 @@ class _SettingsPageState extends State<SettingsPage> {
}
}

/// the widget that shows a settings option
class SettingsOption extends StatelessWidget {
final String title;
final String subtitle;
Expand Down Expand Up @@ -177,6 +180,7 @@ class SettingsOption extends StatelessWidget {
}
}

/// about the app page
class AboutPage extends StatefulWidget {
const AboutPage({Key? key}) : super(key: key);

Expand Down Expand Up @@ -333,6 +337,7 @@ class _AboutPageState extends State<AboutPage> {
}
}

/// showing an option about the app
class AboutCard extends StatelessWidget {
final String? title;
final String? subtitle;
Expand Down
16 changes: 12 additions & 4 deletions lib/pages/status_preview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import 'package:video_player/video_player.dart';
import 'package:share_plus/share_plus.dart';
import 'package:filesystem_picker/filesystem_picker.dart';

class PreviewPage extends StatefulWidget {
/// the page that shows the preview of the status
class StatusPreviewPage extends StatefulWidget {
final File file;
const PreviewPage({Key? key, required this.file}) : super(key: key);
const StatusPreviewPage({Key? key, required this.file}) : super(key: key);

@override
State<PreviewPage> createState() => _PreviewPageState();
State<StatusPreviewPage> createState() => _StatusPreviewPageState();
}

class _PreviewPageState extends State<PreviewPage> {
class _StatusPreviewPageState extends State<StatusPreviewPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -21,6 +22,7 @@ class _PreviewPageState extends State<PreviewPage> {
child: Builder(
builder: (context) {
if (widget.file.path.endsWith('.mp4')) {
// if the media file is a video
return Column(
children: [
StatusPlayer(
Expand Down Expand Up @@ -67,6 +69,7 @@ class _PreviewPageState extends State<PreviewPage> {
],
);
} else if (widget.file.path.endsWith('.jpg')) {
// or if its a picture
return Stack(
children: [
Center(
Expand All @@ -87,6 +90,7 @@ class _PreviewPageState extends State<PreviewPage> {
children: [
TextButton(
onPressed: () {
// sharing the status
Share.shareFiles(
[widget.file.path],
);
Expand All @@ -95,6 +99,7 @@ class _PreviewPageState extends State<PreviewPage> {
),
TextButton(
onPressed: () async {
// copying the status to another directory
String? path = await FilesystemPicker.open(
title: 'Save to folder',
context: context,
Expand Down Expand Up @@ -135,6 +140,7 @@ class _PreviewPageState extends State<PreviewPage> {
}
}

/// this plays the status
class StatusPlayer extends StatefulWidget {
final File file;
const StatusPlayer({Key? key, required this.file}) : super(key: key);
Expand Down Expand Up @@ -216,6 +222,8 @@ class _StatusPlayerState extends State<StatusPlayer> {
}
}

/// this shows the position of the video
/// and also you can seek to a specific position
class PlayerPosIndicator extends StatefulWidget {
final VideoPlayerController controller;
const PlayerPosIndicator({Key? key, required this.controller})
Expand Down
25 changes: 22 additions & 3 deletions lib/pages/statuses_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:whatskit/widgets/status_card.dart';
import 'package:device_info_plus/device_info_plus.dart';

class Permissions {
/// this is like a middleware
/// different android versions use different type of permissions for the same thing
/// in this case android 11 needs the manageExternalStorage permission to work
class _Permissions {
late AndroidDeviceInfo _androidDeviceInfo;
int? androidVersion;

Permissions() {
_Permissions() {
_init();
}

/// returns ```true``` if the permission is granted
Future<bool> get isGranted async {
if (androidVersion == null) {
_androidDeviceInfo = await DeviceInfoPlugin().androidInfo;
Expand All @@ -24,6 +28,7 @@ class Permissions {
}
}
/// requests permissions if they have not been granted
Future<PermissionStatus> requestIfNotFound() async {
if (await isGranted == false) {
return await requestPermission();
Expand All @@ -32,17 +37,20 @@ class Permissions {
}
}
/// requests permissions
Future<PermissionStatus> requestPermission() async {
return await Permission.manageExternalStorage.request();
}
/// async init function of the class
Future<void> _init() async {
_androidDeviceInfo = await DeviceInfoPlugin().androidInfo;
androidVersion = int.parse(_androidDeviceInfo.version.release ?? '0');
requestIfNotFound();
}
}
/// page that shows the statuses
class StatusesPage extends StatefulWidget {
const StatusesPage({Key? key}) : super(key: key);
Expand All @@ -53,13 +61,18 @@ class StatusesPage extends StatefulWidget {
class _StatusesPageState extends State<StatusesPage> {
bool? isWhatsappInstalled;
bool? isPermissionGranted;
/// list of statuses
List<FileSystemEntity> _statusFiles = [];
final Permissions _permissions = Permissions();
final _Permissions _permissions = _Permissions();
// returns a list of Status files from the statuses dir
Future<List<FileSystemEntity>> getFileList() async {
/// dir that has all the statuses
Directory dir = Directory(
'/storage/emulated/0/Android/media/com.whatsapp/Whatsapp/Media/.Statuses/');
List<FileSystemEntity> fileList = await dir.list(recursive: false).toList();
// we only wants the media files
return fileList.where((element) {
return element.path.endsWith('.mp4') || element.path.endsWith('.jpg');
}).toList();
Expand Down Expand Up @@ -95,10 +108,13 @@ class _StatusesPageState extends State<StatusesPage> {
@override
Widget build(BuildContext context) {
if (isWhatsappInstalled == null || isPermissionGranted == null) {
// showing a loading circle while everything is verifying
return const Center(
child: CircularProgressIndicator(),
);
} else if (!isPermissionGranted!) {
// if we dont have the permission
// we display a screen so the user can grant it
return GestureDetector(
onTap: () async {
PermissionStatus permissionGranted =
Expand Down Expand Up @@ -134,6 +150,7 @@ class _StatusesPageState extends State<StatusesPage> {
),
);
} else if (isWhatsappInstalled == false) {
// the screen that we show if the whatsapp isn't installed
return Scaffold(
body: Center(
child: Column(
Expand All @@ -154,12 +171,14 @@ class _StatusesPageState extends State<StatusesPage> {
),
);
} else {
// if every thing is oky we show the page
return Scaffold(
body: RefreshIndicator(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
onRefresh: _init,
child: _statusFiles.isEmpty
? Column(
// when there are no statuses
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(
Expand Down
27 changes: 27 additions & 0 deletions lib/pages/trimmed_video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:video_trimmer/video_trimmer.dart';

/// shows the trimmed version of a video
/// also users can manually trim the video and share it individually
class TrimmedVideoPage extends StatefulWidget {
/// the position which the trim starts
final Duration start;

/// the position which the trim ends
final Duration end;

/// video file we are trimming
final File video;
const TrimmedVideoPage({
Key? key,
Expand All @@ -19,9 +26,16 @@ class TrimmedVideoPage extends StatefulWidget {
}

class _TrimmedVideoPageState extends State<TrimmedVideoPage> {
/// trimmer controller
Trimmer? _trimmer;

/// whether the video is being played or not
bool? _isPlaying;

/// the starting position of the trim in milliseconds
double? _trimStart;

/// the ending position of the trim in milliseconds
double? _trimEnd;

@override
Expand All @@ -30,6 +44,7 @@ class _TrimmedVideoPageState extends State<TrimmedVideoPage> {
super.initState();
}

/// async init function of the class
Future<void> _init() async {
_trimmer = Trimmer();
await _trimmer!.loadVideo(videoFile: widget.video);
Expand Down Expand Up @@ -162,9 +177,15 @@ class _TrimmedVideoPageState extends State<TrimmedVideoPage> {
}
}

/// indicating the position of the video
class TrimmerPosIndicator extends StatefulWidget {
/// the trimmer controller
final Trimmer trimmer;

/// the starting position of the trim in milliseconds
final double trimStart;

/// the ending position of the trim in milliseconds
final double trimEnd;
const TrimmerPosIndicator({
Key? key,
Expand All @@ -178,8 +199,14 @@ class TrimmerPosIndicator extends StatefulWidget {
}

class _TrimmerPosIndicatorState extends State<TrimmerPosIndicator> {
/// minimum value of the slider
double min = 0;

/// maximum value of the slider
double max = 100;

/// the current value of the slider
/// position of the video
double position = 0;

void _update() {
Expand Down
Loading

0 comments on commit 8697af9

Please sign in to comment.