Skip to content

Commit

Permalink
praso app improvementssss. commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Usama committed Nov 2, 2021
1 parent 0e9767f commit 3386aec
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 26 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:label="praso"
android:label="Praso"
android.bundle.enableUncompressedNativeLibs="false"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
16 changes: 11 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:praso/home_screen.dart';
import 'package:praso/web_view_redirect.dart';
import 'package:provider/provider.dart';

ConnectivityResult? connectivityResult;
ConnectionState? connectionState;
double screenWidth = 0.0;
void main() {
runApp( const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
title: 'Praso App',
runApp( MultiProvider(
providers: [
ChangeNotifierProvider<PrasoNotifyProvider>(create: (context) => PrasoNotifyProvider(),)
],
child: const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
title: 'Praso App',
),
));
}
class MyApp extends StatefulWidget {
Expand All @@ -32,7 +38,7 @@ void main() {
));
screenWidth = MediaQuery.of(context).size.width;

Future.delayed(const Duration(seconds: 1), () async{
Future.delayed(const Duration(seconds: 1), () async {
connectivityResult = await Connectivity().checkConnectivity();
switch (connectivityResult!) {
case ConnectivityResult.mobile:
Expand Down
69 changes: 50 additions & 19 deletions lib/web_view_redirect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';

Expand All @@ -18,6 +19,8 @@ class _WebViewPageState extends State<WebViewPage> {
WebViewController? _webViewController;
String? currentWebUrl;
bool whatsAppVisibility = true;
Timer? timer;
PrasoNotifyProvider? prasoNotifyProvider;

final Completer<WebViewController> _controllerCompleter = Completer<WebViewController>();

Expand Down Expand Up @@ -49,12 +52,6 @@ class _WebViewPageState extends State<WebViewPage> {
}
}

@override
void initState() {
WebView.platform = SurfaceAndroidWebView();
super.initState();
}

Widget bottomNavigationBarItems({required String imagePath, required String iconText}) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -72,9 +69,28 @@ class _WebViewPageState extends State<WebViewPage> {
);
}

@override
void initState() {
prasoNotifyProvider = Provider.of(context,listen: false);
WebView.platform = SurfaceAndroidWebView();
timer = Timer.periodic(const Duration(seconds: 2), (timer) async{
currentWebUrl = await _webViewController!.currentUrl();
print('url.........$currentWebUrl');
prasoNotifyProvider!.url = currentWebUrl!;
});
super.initState();
}

@override
void dispose() {
timer!.cancel();
super.dispose();
}


@override
Widget build(BuildContext context) {
print('build invoked');
return SafeArea(
child: WillPopScope(
onWillPop: () async {
Expand Down Expand Up @@ -116,9 +132,7 @@ class _WebViewPageState extends State<WebViewPage> {
onWebViewCreated: (WebViewController webViewController) {
_controllerCompleter.future.then((value) => _webViewController = value);
_controllerCompleter.complete(webViewController);
print('web view created invoked');
webViewController.currentUrl().then((value) => currentWebUrl = value!);
print('...........$currentWebUrl');
},
),
Positioned(
Expand All @@ -139,27 +153,33 @@ class _WebViewPageState extends State<WebViewPage> {
_webViewController!.goBack();
}
},
child: bottomNavigationBarItems(imagePath: 'assets/images/home_icon.jpg', iconText: 'Home Page')),
child: bottomNavigationBarItems(imagePath: 'assets/images/home_icon.jpg', iconText: 'inicio')),

GestureDetector(
onTap: () {

},
child: bottomNavigationBarItems(imagePath: 'assets/images/categories_icon.png', iconText: 'Categories')),
child: bottomNavigationBarItems(imagePath: 'assets/images/categories_icon.png', iconText: 'categorias')),

GestureDetector(
onTap: () {
_webViewController!.loadUrl('https://praso.com.br/account/login?return_url=%2Faccount');
},
child: bottomNavigationBarItems(imagePath: 'assets/images/contact_Icon.png', iconText: 'account')),

Visibility(
visible: currentWebUrl != null ? currentWebUrl!.contains('praso') : true,
child: GestureDetector(
onTap: () {
openWhatsApp();
},
child: bottomNavigationBarItems(imagePath: 'assets/images/whats_app_icon.png', iconText: 'Whats app')),
child: bottomNavigationBarItems(imagePath: 'assets/images/contact_Icon.png', iconText: 'conta')),

Selector<PrasoNotifyProvider, String>(
selector: (context, prasoNotifyProvider) => prasoNotifyProvider.url,
builder: (context, value, child) {
print('builderrrrrr');
return Visibility(
visible: currentWebUrl != null ? currentWebUrl!.contains('praso.com.br') : true,
child: GestureDetector(
onTap: () {
openWhatsApp();
},
child: bottomNavigationBarItems(imagePath: 'assets/images/whats_app_icon.png', iconText: 'Whats app')),
);
},
),
],
)
Expand All @@ -173,3 +193,14 @@ class _WebViewPageState extends State<WebViewPage> {
}
}

class PrasoNotifyProvider with ChangeNotifier {
String _url = '';

String get url => _url;

set url(String value) {
_url = value;
notifyListeners();
}
}

16 changes: 15 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
nm:
dependency: transitive
description:
Expand Down Expand Up @@ -205,6 +212,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -328,7 +342,7 @@ packages:
name: webview_flutter_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
webview_flutter_wkwebview:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
url_launcher: ^6.0.12
webview_flutter: ^2.1.1
connectivity_plus: ^2.0.2
provider: ^6.0.1
# data_connection_checker: ^0.3.4

dev_dependencies:
Expand Down

0 comments on commit 3386aec

Please sign in to comment.