Skip to content

Commit

Permalink
💎 fix errorMessage (webm 🔊 edia) and remove print 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
devfemibadmus committed Aug 27, 2024
1 parent a3ed57c commit 3eab2d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
23 changes: 9 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ class _MyHomePageState extends State<MyHomePage> {
_isProcessing = false;
_dataLoaded = true;
});
print("_dataLoaded: $_dataLoaded");
// print("_dataLoaded: $_dataLoaded");
}

Future<void> _continuousMethods() async {
print("_continuousMethods");
// print("_continuousMethods");
if (tabs[_currentIndex]['appType'] != 'WEBMEDIA') {
setState(() {
_isProcessing = true;
Expand All @@ -281,25 +281,20 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> startService() async {
print("starting....");
try {
await platform.invokeMethod('startService').then((value) {
if (!_isProcessing) {
_continuousMethods();
}
});
} on PlatformException catch (e) {
print("Failed to start service: '${e.message}'.");
}
await platform.invokeMethod('startService').then((value) {
if (!_isProcessing) {
_continuousMethods();
}
});
}

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
DateTime currentDate = DateTime.now();
if (currentDate.year >= 2024 &&
currentDate.month >= 8 &&
currentDate.day >= 30) {
currentDate.month >= 9 &&
currentDate.day >= 15) {
return Center(
child: GestureDetector(
onTap: () async => await platform.invokeMethod('launchUpdate'),
Expand Down
3 changes: 2 additions & 1 deletion lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ Future<Map<String, dynamic>?> fetchMediaFromServer(String url) async {
Api(apiUrl: 'https://devfemibadmus.blackstackhub.com/webmedia/api/');

final data = await api.fetchMedia(url);
if (data != null && data['success']) {
// print("data: $data");
if (data != null && data['success'] != null) {
return {
'success': true,
'data': WebMedia.fromJson(data['data']),
Expand Down
12 changes: 4 additions & 8 deletions lib/pages/webMedia/webmedias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class WebMedias extends StatefulWidget {

class WebMediasState extends State<WebMedias>
with AutomaticKeepAliveClientMixin<WebMedias> {
String? errorMessage;
WebMedia? mediaData;
Map<int, bool> isDownloadingMap = {};
double downloadPercentage = 0.0;
late TextEditingController _textController;
late FocusNode _focusNode;
String? errorMessage;
Media? selectedQuality;
@override
bool get wantKeepAlive => true;
Expand Down Expand Up @@ -47,30 +47,25 @@ class WebMediasState extends State<WebMedias>
mediaData = null;
CustomOverlay().showOverlayLoader(context);
});

if (isSupportUrl(_textController.text)) {
final response = await fetchMediaFromServer(_textController.text);

setState(() {
if (response != null && response.containsKey('success')) {
if (response != null && response['success'] != null) {
mediaData = response['data'];
if (mediaData?.medias?.isNotEmpty ?? false) {
selectedQuality = mediaData!.medias!.first;
}
CustomOverlay().removeOverlayLoader();
} else {
mediaData = null;
CustomOverlay().removeOverlayLoader();
errorMessage = response?['message'] ?? 'Try again!';
}
});
} else {
setState(() {
mediaData = null;
CustomOverlay().removeOverlayLoader();
errorMessage = 'Not a valid URL';
});
}
CustomOverlay().removeOverlayLoader();
}

void onDownloadPressed(int index) async {
Expand Down Expand Up @@ -108,6 +103,7 @@ class WebMediasState extends State<WebMedias>
child: Column(
children: <Widget>[
WebMediaForm(
errorMessage: errorMessage,
onUrlChanged: onUrlChanged,
onPasteButtonPressed: onPasteButtonPressed,
textController: _textController,
Expand Down
19 changes: 4 additions & 15 deletions lib/pages/webMedia/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class WebMediaForm extends StatefulWidget {
required this.onUrlChanged,
required this.onPasteButtonPressed,
required this.textController,
required this.errorMessage,
});

final Function(String) onUrlChanged;
final Function() onPasteButtonPressed;
final TextEditingController textController;
final String? errorMessage;

@override
WebMediaFormState createState() => WebMediaFormState();
Expand All @@ -20,7 +22,6 @@ class WebMediaForm extends StatefulWidget {
class WebMediaFormState extends State<WebMediaForm> {
late FocusNode _focusNode;
String pastebtn = "Paste";
String? errorMessage;

@override
void initState() {
Expand Down Expand Up @@ -64,7 +65,7 @@ class WebMediaFormState extends State<WebMediaForm> {
cursorColor: Theme.of(context).primaryColor,
decoration: InputDecoration(
border: const OutlineInputBorder(),
errorText: errorMessage,
errorText: widget.errorMessage,
labelText: 'Media URL',
labelStyle: TextStyle(color: Theme.of(context).primaryColor),
contentPadding: const EdgeInsets.all(5.0),
Expand All @@ -81,26 +82,14 @@ class WebMediaFormState extends State<WebMediaForm> {
const SizedBox(width: 15),
TextButton(
onPressed: () async {
_focusNode
.unfocus(); // Unfocus the text field to trigger the focus change
setState(() {
errorMessage = null;
});
_focusNode.unfocus();

final value = await fetchClipboardContent();

if (pastebtn == "Paste") {
widget.textController.text = value;
}

setState(() {
if (isSupportUrl(widget.textController.text)) {
errorMessage = null;
} else {
errorMessage = 'Not a valid URL';
}
});

widget.onPasteButtonPressed();
},
style: ElevatedButton.styleFrom(
Expand Down

0 comments on commit 3eab2d1

Please sign in to comment.