diff --git a/example/README.md b/example/README.md index cddea5d..e9fda31 100644 --- a/example/README.md +++ b/example/README.md @@ -1,30 +1,49 @@ ## Usage ``` -Future getLinks() async { - await LinkPreview.getPreview('https://flutter.dev', - onData: (PreviewResponse data) => _previewData(data), - onError: (error) => _handleError(error)); +Future getLinks() async { + try { + PreviewResponse previewResponse = await LinkPreview.getPreview('https://google.com'); + _previewData(previewResponse); + + PreviewResponse previewResponse2 = await LinkPreview.getPreview('https://facebook.com'); + _previewData(previewResponse2); + + PreviewResponse previewResponse3 = await LinkPreview.getPreview('https://amazon.com'); + _previewData(previewResponse3); + } on PlatformException { + print('Error occured!!'); + } } _previewData(PreviewResponse previewResponse) { - // Preview status can be `complete` (handle data) or `loading` (show loading indicator) - if (previewResponse.status == PreviewStatus.complete) { - print('Received status: ${previewResponse.status}'); - print('Received title: ${previewResponse.title}'); - print('Received description: ${previewResponse.description}'); - print('Received image: ${previewResponse.image}'); - print('Received url: ${previewResponse.url}'); - print('Received final url: ${previewResponse.finalUrl}'); - print('Received cannonical url: ${previewResponse.cannonicalUrl}'); - print('Received html code: ${previewResponse.htmlCode}'); - print('Received row: ${previewResponse.row}'); - } else { - print('Received status: ${previewResponse.status}'); - } - } - - _handleError(error) { - print('Received error: ${error.message}'); + if (previewResponse.status == PreviewStatus.success) { + print('==============================================='); + print('Received status: ${previewResponse.status}'); + print('Received title: ${previewResponse.title}'); + print('Received description: ${previewResponse.description}'); + print('Received image: ${previewResponse.image}'); + print('Received url: ${previewResponse.url}'); + print('Received final url: ${previewResponse.finalUrl}'); + print('Received cannonical url: ${previewResponse.cannonicalUrl}'); + print('Received html code: ${previewResponse.htmlCode}'); + print('Received row: ${previewResponse.row}'); + print('==============================================='); + } else if (previewResponse.status == PreviewStatus.wrongUrlError) { + print('==============================================='); + print('Received status: ${previewResponse.status}'); + print('Wrong URL'); + print('==============================================='); + } else if (previewResponse.status == PreviewStatus.parsingError) { + print('==============================================='); + print('Received status: ${previewResponse.status}'); + print('Parsing URL error'); + print('==============================================='); + } else { + print('==============================================='); + print('Received status: ${previewResponse.status}'); + print('Other error'); + print('==============================================='); + } } ``` \ No newline at end of file