Skip to content

Commit

Permalink
story(roadtripper): implemented waze deep linking (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaba505 committed Jul 4, 2023
1 parent 6f14cf5 commit 99d5b3c
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 2 deletions.
11 changes: 11 additions & 0 deletions roadtrips/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@
android:name="flutterEmbedding"
android:value="2" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="waze" />
</intent>
</queries>
</manifest>
2 changes: 2 additions & 0 deletions roadtrips/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:roadtrips/screens/destination_details.dart';
import 'package:roadtrips/screens/home.dart';
import 'package:roadtrips/screens/search.dart';
import 'package:roadtrips/screens/suggestions.dart';
Expand All @@ -23,6 +24,7 @@ class MyApp extends StatelessWidget {
HomeScreen.route,
SearchScreen.route,
SuggestionsScreen.route,
DestinationDetailsScreen.route,
];

@override
Expand Down
132 changes: 132 additions & 0 deletions roadtrips/lib/screens/destination_details.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import 'package:flutter/material.dart';
import 'package:roadtrips/screens/suggestions.dart';
import 'package:url_launcher/url_launcher.dart';

class DestinationDetailsScreen extends StatefulWidget {
static (String, Widget Function(BuildContext)) route =
('/destination/details', (context) => const DestinationDetailsScreen());

const DestinationDetailsScreen({super.key});

@override
State<DestinationDetailsScreen> createState() => _DestinationDetailsState();
}

class _DestinationDetailsState extends State<DestinationDetailsScreen> {
bool showBottomSheet = false;

@override
Widget build(BuildContext context) {
final destination =
ModalRoute.of(context)!.settings.arguments as Destination;

return Scaffold(
appBar: AppBar(
title: const Text('Destination Details'),
actions: [
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
height: 80,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
),
gradient: LinearGradient(
colors: [Colors.grey[300]!, Colors.grey[200]!],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: const [.35, 0],
),
),
child: Column(
children: [
Container(
margin: const EdgeInsets.only(top: 12.5),
height: 3,
width: 30,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5)),
),
GestureDetector(
onTap: () {
var uri = Uri.parse(destination.wazeDeepLink);
launchUrl(uri,
mode:
LaunchMode.externalNonBrowserApplication);
},
child: Container(
margin: const EdgeInsets.only(top: 9.5),
child: Container(
margin: const EdgeInsets.only(
top: 17.5, left: 17.5),
alignment: Alignment.centerLeft,
child: const Text(
'Open in Waze',
textScaleFactor: 1.15,
),
),
),
),
],
),
);
});
},
),
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
destination.name,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
Text(
'Latitude',
style: TextStyle(
color: Colors.grey[700]!,
),
),
Text(
destination.latitude.toString(),
style: const TextStyle(fontWeight: FontWeight.w500),
),
],
),
Column(
children: [
Text(
'Longitude',
style: TextStyle(
color: Colors.grey[700]!,
),
),
Text(
destination.longitude.toString(),
style: const TextStyle(fontWeight: FontWeight.w500),
),
],
)
],
)
],
),
);
}
}
17 changes: 15 additions & 2 deletions roadtrips/lib/screens/suggestions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ const String suggestionsQuery = """
latitude
longitude
name
wazeDeeplink
}
}""";

class Destination {
final double latitude;
final double longitude;
final String name;
final String wazeDeepLink;

const Destination(this.latitude, this.longitude, this.name);
const Destination(
this.latitude, this.longitude, this.name, this.wazeDeepLink);
}

class SuggestionsScreen extends StatelessWidget {
Expand Down Expand Up @@ -68,8 +71,18 @@ class SuggestionsScreen extends StatelessWidget {

return ListView(
children: destinations
.map((destination) => Destination(
destination['latitude'],
destination['longitude'],
destination['name'],
destination['wazeDeeplink'],
))
.map((destination) => ListTile(
title: Text(destination['name']),
title: Text(destination.name),
onTap: () {
Navigator.pushNamed(context, '/destination/details',
arguments: destination);
},
))
.toList(),
);
Expand Down
64 changes: 64 additions & 0 deletions roadtrips/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: eb1e00ab44303d50dd487aab67ebc575456c146c6af44422f9c13889984c00f3
url: "https://pub.dev"
source: hosted
version: "6.1.11"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "15f5acbf0dce90146a0f5a2c4a002b1814a6303c4c5c075aa2623b2d16156f03"
url: "https://pub.dev"
source: hosted
version: "6.0.36"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "9af7ea73259886b92199f9e42c116072f05ff9bea2dcb339ab935dfc957392c2"
url: "https://pub.dev"
source: hosted
version: "6.1.4"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "207f4ddda99b95b4d4868320a352d374b0b7e05eefad95a4a26f57da413443f5"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "91ee3e75ea9dadf38036200c5d3743518f4a5eb77a8d13fda1ee5764373f185e"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: bfdfa402f1f3298637d71ca8ecfe840b4696698213d5346e9d12d4ab647ee2ea
url: "https://pub.dev"
source: hosted
version: "2.1.3"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "6bb1e5d7fe53daf02a8fee85352432a40b1f868a81880e99ec7440113d5cfcab"
url: "https://pub.dev"
source: hosted
version: "2.0.17"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "254708f17f7c20a9c8c471f67d86d76d4a3f9c1591aad1e15292008aceb82771"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
uuid:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions roadtrips/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
graphql_flutter: ^5.1.2
url_launcher: ^6.1.11

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 99d5b3c

Please sign in to comment.