-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix quicklinks * Move import * Open link in app * Add link web view test and make webView work on IOS * Surround launchInBrowser in try catch * Move logic to a viewmodel and add/fix tests * Pass quicklink instead of only the link and add await on github_api refactor * Fix tests and reorder imports * Refactor to use ViewModelBuilder * Add progressbar while the page is loading * Fix test * Use buildLoading and add verify no more interfactions * Use baseScaffold Co-authored-by: Camille Brulotte <[email protected]> Co-authored-by: Camille Brulotte <>
- Loading branch information
1 parent
80cb15d
commit a773a3f
Showing
15 changed files
with
343 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// FLUTTER / DART / THIRD-PARTIES | ||
import 'dart:io'; | ||
import 'package:package_info/package_info.dart'; | ||
|
||
class InternalInfoService { | ||
|
||
// Build the error message with the current device informations | ||
Future<String> getDeviceInfoForErrorReporting() async { | ||
final PackageInfo packageInfo = await PackageInfo.fromPlatform(); | ||
|
||
return "**Device Infos** \n" | ||
"- **Version:** ${packageInfo.version} \n" | ||
"- **Build number:** ${packageInfo.buildNumber} \n" | ||
"- **Platform operating system:** ${Platform.operatingSystem} \n" | ||
"- **Platform operating system version:** ${Platform.operatingSystemVersion} \n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// FLUTTER / DART / THIRD-PARTIES | ||
import 'package:notredame/core/models/quick_link.dart'; | ||
import 'package:stacked/stacked.dart'; | ||
|
||
// MODELS | ||
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
|
||
// CONSTANTS | ||
import 'package:notredame/core/constants/router_paths.dart'; | ||
|
||
// SERVICES | ||
import 'package:notredame/core/services/analytics_service.dart'; | ||
import 'package:notredame/core/services/navigation_service.dart'; | ||
import 'package:notredame/core/services/internal_info_service.dart'; | ||
|
||
// UTILS | ||
import 'package:notredame/ui/utils/app_theme.dart'; | ||
|
||
// OTHER | ||
import 'package:notredame/locator.dart'; | ||
|
||
class WebLinkCardViewModel extends BaseViewModel { | ||
|
||
/// used to redirect on the security. | ||
final NavigationService _navigationService = locator<NavigationService>(); | ||
|
||
final AnalyticsService _analyticsService = locator<AnalyticsService>(); | ||
|
||
final InternalInfoService _internalInfoService = locator<InternalInfoService>(); | ||
|
||
/// used to open a website or the security view | ||
Future<void> onLinkClicked(QuickLink link) async { | ||
if (link.link == 'security') { | ||
_navigationService.pushNamed(RouterPaths.security); | ||
} else { | ||
try { | ||
await launchInBrowser(link.link); | ||
} catch (error) { | ||
await launchWebView(error.toString(), link); | ||
} | ||
} | ||
} | ||
|
||
/// used to open a website inside AndroidChromeCustomTabs or SFSafariViewController | ||
Future<void> launchInBrowser(String url) async { | ||
final ChromeSafariBrowser browser = ChromeSafariBrowser(); | ||
await browser.open( | ||
url: Uri.parse(url), | ||
options: ChromeSafariBrowserClassOptions( | ||
android: AndroidChromeCustomTabsOptions( | ||
addDefaultShareMenuItem: false, | ||
enableUrlBarHiding: true, | ||
toolbarBackgroundColor: AppTheme.etsLightRed), | ||
ios: IOSSafariOptions( | ||
barCollapsingEnabled: true, | ||
preferredBarTintColor: AppTheme.etsLightRed))); | ||
} | ||
|
||
Future<void> launchWebView(String error, QuickLink link) async { | ||
final String errorMessage = await _internalInfoService.getDeviceInfoForErrorReporting(); | ||
|
||
_analyticsService.logError("web_link_card", "**Error message : $error\n$errorMessage"); | ||
_navigationService.pushNamed(RouterPaths.webView, arguments: link); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// FLUTTER / DART / THIRD-PARTIES | ||
import 'package:flutter/material.dart'; | ||
import 'package:webview_flutter/webview_flutter.dart'; | ||
|
||
// MODELS | ||
import 'package:notredame/core/models/quick_link.dart'; | ||
|
||
// WIDGETS | ||
import 'package:notredame/ui/widgets/base_scaffold.dart'; | ||
|
||
class LinkWebView extends StatefulWidget { | ||
final QuickLink _links; | ||
|
||
const LinkWebView(this._links); | ||
|
||
@override | ||
_LinkWebViewState createState() => _LinkWebViewState(); | ||
} | ||
|
||
class _LinkWebViewState extends State<LinkWebView> { | ||
bool isLoading = true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BaseScaffold( | ||
isLoading: isLoading, | ||
showBottomBar: false, | ||
appBar: AppBar( | ||
title: Text(widget._links.name), | ||
), | ||
body: Stack( | ||
children: <Widget>[ | ||
WebView( | ||
initialUrl: widget._links.link, | ||
javascriptMode: JavascriptMode.unrestricted, | ||
onPageFinished: (finish) { | ||
setState(() { | ||
isLoading = false; | ||
}); | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,56 @@ | ||
// FLUTTER / DART / THIRD-PARTIES | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; | ||
import 'package:stacked/stacked.dart'; | ||
|
||
// CONSTANT | ||
import 'package:notredame/core/constants/router_paths.dart'; | ||
// VIEWMODEL | ||
import 'package:notredame/core/viewmodels/web_link_card_viewmodel.dart'; | ||
|
||
// MODEL | ||
import 'package:notredame/core/models/quick_link.dart'; | ||
|
||
// SERVICE | ||
import 'package:notredame/core/services/navigation_service.dart'; | ||
|
||
// OTHER | ||
import 'package:notredame/locator.dart'; | ||
// UTILS | ||
import 'package:notredame/ui/utils/app_theme.dart'; | ||
|
||
class WebLinkCard extends StatelessWidget { | ||
final QuickLink _links; | ||
|
||
/// used to redirect on the security. | ||
final NavigationService _navigationService = locator<NavigationService>(); | ||
|
||
WebLinkCard(this._links); | ||
const WebLinkCard(this._links); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: MediaQuery.of(context).size.width / 3.1, | ||
height: 130, | ||
child: Card( | ||
elevation: 4.0, | ||
child: InkWell( | ||
onTap: () => _onLinkClicked(_links.link), | ||
splashColor: AppTheme.etsLightRed.withAlpha(50), | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Column( | ||
children: [ | ||
Expanded( | ||
flex: 40, | ||
child: Image.asset(_links.image, color: AppTheme.etsLightRed), | ||
), | ||
FittedBox( | ||
fit: BoxFit.fitWidth, | ||
child: Text( | ||
_links.name, | ||
style: const TextStyle(color: Colors.red, fontSize: 18.0), | ||
), | ||
Widget build(BuildContext context) => | ||
ViewModelBuilder<WebLinkCardViewModel>.reactive( | ||
viewModelBuilder: () => WebLinkCardViewModel(), | ||
builder: (context, model, child) { | ||
return SizedBox( | ||
width: MediaQuery.of(context).size.width / 3.1, | ||
height: 130, | ||
child: Card( | ||
elevation: 4.0, | ||
child: InkWell( | ||
onTap: () => model.onLinkClicked(_links), | ||
splashColor: AppTheme.etsLightRed.withAlpha(50), | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Column( | ||
children: [ | ||
Expanded( | ||
flex: 40, | ||
child: Image.asset(_links.image, color: AppTheme.etsLightRed), | ||
), | ||
FittedBox( | ||
fit: BoxFit.fitWidth, | ||
child: Text( | ||
_links.name, | ||
style: const TextStyle(color: Colors.red, fontSize: 18.0), | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
); | ||
} | ||
|
||
/// used to open a website or the security view | ||
void _onLinkClicked(String link) { | ||
if (link == 'security') { | ||
_navigationService.pushNamed(RouterPaths.security); | ||
} else { | ||
_launchInBrowser(link); | ||
} | ||
} | ||
|
||
/// used to open a website inside AndroidChromeCustomTabs or SFSafariViewController | ||
Future<void> _launchInBrowser(String url) async { | ||
final ChromeSafariBrowser browser = ChromeSafariBrowser(); | ||
await browser.open( | ||
url: Uri.parse(url), | ||
options: ChromeSafariBrowserClassOptions( | ||
android: AndroidChromeCustomTabsOptions( | ||
addDefaultShareMenuItem: false, | ||
enableUrlBarHiding: true, | ||
toolbarBackgroundColor: Colors.red), | ||
ios: IOSSafariOptions( | ||
barCollapsingEnabled: true, | ||
preferredBarTintColor: Colors.red))); | ||
} | ||
} | ||
|
Oops, something went wrong.