Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Crash report + default beer icon + better untappd integration
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitletondor committed May 23, 2018
1 parent 41104f6 commit 504aa21
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 33 deletions.
6 changes: 6 additions & 0 deletions beer_me_up.iml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/google_sign_in/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/google_sign_in/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/google_sign_in/example/build" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/.pub" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/build" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/path_provider/example/build" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/shared_preferences-0.4.0/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/shared_preferences-0.4.0/.pub" />
<excludeFolder url="file://$MODULE_DIR$/ios/Pods/.symlinks/plugins/shared_preferences-0.4.0/build" />
Expand Down
Binary file removed fonts/beers.ttf
Binary file not shown.
Binary file added images/2.0x/default_beer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/3.0x/default_beer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/default_beer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions lib/common/exceptionprint.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:beer_me_up/main.dart';
import 'package:sentry/sentry.dart';

void printException(dynamic e, StackTrace stackTrace, [String message]) {
if( message != null ) {
Expand All @@ -7,5 +9,12 @@ void printException(dynamic e, StackTrace stackTrace, [String message]) {
debugPrint(e.toString());
}

final Event event = new Event(
exception: e,
stackTrace: stackTrace,
message: message,
);
BeerMeUpApp.sentry.capture(event: event);

print(stackTrace);
}
5 changes: 4 additions & 1 deletion lib/common/widget/beertile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class BeerTile extends StatelessWidget {
Widget _buildThumbnailImage(Beer beer) {
Widget image;
if (beer.label?.iconUrl == null) {
image = const Icon(IconData(0xe900, fontFamily: "beers"));
image = Container(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Image.asset("images/default_beer.png"),
);
} else {
image = CachedNetworkImage(
imageUrl: beer.label.iconUrl,
Expand Down
10 changes: 9 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ import 'package:beer_me_up/page/login/loginpage.dart';
import 'package:beer_me_up/page/checkin/checkinpage.dart';
import 'package:beer_me_up/page/settings/settingspage.dart';
import 'package:beer_me_up/service/analytics.dart';
import 'package:beer_me_up/service/authenticationservice.dart';
import 'package:sentry/sentry.dart';
import 'package:beer_me_up/private.dart';
import 'package:beer_me_up/common/exceptionprint.dart';

void main() => runApp(BeerMeUpApp());

class BeerMeUpApp extends StatelessWidget {
static OptOutAwareFirebaseAnalytics analytics = OptOutAwareFirebaseAnalytics(FirebaseAnalytics());
static Config config = Config.create();
static SentryClient sentry = new SentryClient(dsn: SENTRY_DSN);

@override
Widget build(BuildContext context) {
config.toString(); // Access object to ensure creation at startup time

// Set-up error reporting
FlutterError.onError = (FlutterErrorDetails error) {
printException(error.exception, error.stack, error.context);
};

return MaterialApp(
title: 'Beer Me Up',
theme: ThemeData(
Expand Down
5 changes: 4 additions & 1 deletion lib/page/checkin/confirm/checkinconfirmpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ class _CheckInConfirmPageState extends ViewState<CheckInConfirmPage, CheckInConf
Widget _buildThumbnailImage(Beer beer) {
Widget image;
if (beer.label?.iconUrl == null) {
image = const Icon(IconData(0xe900, fontFamily: "beers"), color: Colors.black,);
image = Container(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Image.asset("images/default_beer.png"),
);
} else {
image = CachedNetworkImage(
imageUrl: beer.label.iconUrl,
Expand Down
6 changes: 4 additions & 2 deletions lib/page/home/profile/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ProfileViewModel extends BaseViewModel<ProfileState> {

_setStateWithProfileData(ProfileData profileData) {
if( !profileData.hasAllTime && !profileData.hasWeek ) {
setState(ProfileState.empty());
setState(ProfileState.empty(profileData.hasAlreadyCheckedIn));
} else if( profileData.hasWeek && profileData.hasAllTime ) {
setState(ProfileState.load(profileData));
} else if( profileData.hasAllTime ) {
Expand All @@ -130,6 +130,7 @@ class ProfileViewModel extends BaseViewModel<ProfileState> {
class ProfileData {
final bool hasAllTime;
final bool hasWeek;
final bool hasAlreadyCheckedIn;

final BeerStyle favouriteCategory;
final BeerCheckInsData favouriteBeer;
Expand All @@ -139,7 +140,7 @@ class ProfileData {
final int numberOfBeers;
final int weekPoints;

ProfileData(this.hasAllTime, this.hasWeek, this.favouriteBeer, this.favouriteCategory, this.weekBeers, this.numberOfBeers, this.weekPoints, this.totalPoints);
ProfileData(this.hasAllTime, this.hasWeek, this.hasAlreadyCheckedIn, this.favouriteBeer, this.favouriteCategory, this.weekBeers, this.numberOfBeers, this.weekPoints, this.totalPoints);

factory ProfileData.fromData(int totalPoints, List<BeerCheckInsData> checkInsData, List<CheckIn> checkIns) {
final Map<BeerStyle, double> categoriesCounter = Map();
Expand Down Expand Up @@ -187,6 +188,7 @@ class ProfileData {
return ProfileData(
checkInsData.length >= 3,
checkIns.isNotEmpty,
totalPoints > 0,
favouriteBeer,
favouriteCategory,
checkInsList,
Expand Down
66 changes: 46 additions & 20 deletions lib/page/home/profile/profilepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _ProfilePageState extends ViewState<ProfilePage, ProfileViewModel, Profile

return snapshot.data.join(
(loading) => _buildLoadingWidget(),
(empty) => _buildEmptyWidget(),
(empty) => _buildEmptyWidget(empty.hasAlreadyCheckedIn),
(loadNoAllTime) => _buildLoadWidget(loadNoAllTime.profileData),
(loadNoWeek) => _buildLoadWidget(loadNoWeek.profileData),
(load) => _buildLoadWidget(load.profileData),
Expand All @@ -75,7 +75,7 @@ class _ProfilePageState extends ViewState<ProfilePage, ProfileViewModel, Profile
return LoadingWidget();
}

Widget _buildEmptyWidget() {
Widget _buildEmptyWidget(bool hasAlreadyCheckedIn) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -98,10 +98,10 @@ class _ProfilePageState extends ViewState<ProfilePage, ProfileViewModel, Profile
Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Text(
"Check the next beer you have into the app to start your history",
hasAlreadyCheckedIn ? "Continue to check beers you have to build your profile." : "Check the next beer you have into the app to build your profile.",
style: TextStyle(
fontFamily: "Google Sans",
fontSize: 20.0,
fontSize: 18.0,
),
textAlign: TextAlign.center,
),
Expand Down Expand Up @@ -159,24 +159,50 @@ class _ProfilePageState extends ViewState<ProfilePage, ProfileViewModel, Profile
),
),
const Padding(padding: EdgeInsets.only(top: 2.0)),
RichText(
text: TextSpan(
text: "You had ",
style: TextStyle(
fontSize: 16.0,
color: Theme.of(context).textTheme.body1.color,
),
children: <TextSpan> [
TextSpan(
text: "${profileData.numberOfBeers}",
style: const TextStyle(
fontWeight: FontWeight.w500,
),
Offstage(
offstage: profileData.numberOfBeers <= 1,
child: RichText(
text: TextSpan(
text: "You only had ",
style: TextStyle(
fontSize: 16.0,
color: Theme.of(context).textTheme.body1.color,
),
const TextSpan(
text: " different beers",
children: <TextSpan> [
TextSpan(
text: "${profileData.numberOfBeers}",
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
const TextSpan(
text: " beer",
),
],
),
),
),
Offstage(
offstage: profileData.numberOfBeers > 1,
child: RichText(
text: TextSpan(
text: "You had ",
style: TextStyle(
fontSize: 16.0,
color: Theme.of(context).textTheme.body1.color,
),
],
children: <TextSpan> [
TextSpan(
text: "${profileData.numberOfBeers}",
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
const TextSpan(
text: " different beers",
),
],
),
),
),
],
Expand Down
20 changes: 18 additions & 2 deletions lib/page/home/profile/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProfileState extends Union6Impl<
ProfileStateError> union) : super(union);

factory ProfileState.loading() => ProfileState._(factory.first(ProfileStateLoading()));
factory ProfileState.empty() => ProfileState._(factory.second(ProfileStateEmpty()));
factory ProfileState.empty(bool hasAlreadyCheckedIn) => ProfileState._(factory.second(ProfileStateEmpty(hasAlreadyCheckedIn)));
factory ProfileState.loadNoAllTime(ProfileData data) => ProfileState._(factory.third(ProfileStateLoadNoAllTime(data)));
factory ProfileState.loadNoWeek(ProfileData data) => ProfileState._(factory.fourth(ProfileStateLoadNoWeek(data)));
factory ProfileState.load(ProfileData data) => ProfileState._(factory.fifth(ProfileStateLoad(data)));
Expand Down Expand Up @@ -98,7 +98,23 @@ class ProfileStateLoad extends State {
profileData.hashCode;
}

class ProfileStateEmpty extends State {}
class ProfileStateEmpty extends State {
final bool hasAlreadyCheckedIn;

ProfileStateEmpty(this.hasAlreadyCheckedIn);

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ProfileStateEmpty &&
runtimeType == other.runtimeType &&
hasAlreadyCheckedIn == other.hasAlreadyCheckedIn;

@override
int get hashCode =>
super.hashCode ^
hasAlreadyCheckedIn.hashCode;
}

class ProfileStateError extends State {
final String error;
Expand Down
7 changes: 5 additions & 2 deletions lib/private.dart.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const BREWERY_DB_API_KEY = "";
const UNTAPPD_CLIENT_SECRET = "";
const UNTAPPD_CLIENT_ID = "";
const UNTAPPD_CLIENT_SECRET_IOS = "";
const UNTAPPD_CLIENT_ID_IOS = "";
const UNTAPPD_CLIENT_SECRET_ANDROID = "";
const UNTAPPD_CLIENT_ID_ANDROID = "";
const SENTRY_DSN = "";
7 changes: 6 additions & 1 deletion lib/service/beersearch/untappdservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ class UntappdService implements BeerSearchService {
Map<String, String> queryParameters,
}) {
final Map<String, String> queryParams = queryParameters ?? Map();
queryParams.addAll({"client_secret": UNTAPPD_CLIENT_SECRET, "client_id": UNTAPPD_CLIENT_ID});

if( Platform.isIOS ) {
queryParams.addAll({"client_secret": UNTAPPD_CLIENT_SECRET_IOS, "client_id": UNTAPPD_CLIENT_ID_IOS});
} else {
queryParams.addAll({"client_secret": UNTAPPD_CLIENT_SECRET_ANDROID, "client_id": UNTAPPD_CLIENT_ID_ANDROID});
}

return Uri.https(_UNTAPPD_DB_API_ENDPOINT, "/v4/$path", queryParams);
}
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
sentry:
dependency: "direct main"
description:
name: sentry
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -471,6 +478,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.5"
usage:
dependency: transitive
description:
name: usage
url: "https://pub.dartlang.org"
source: hosted
version: "3.4.0"
utf:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies:
firebase_analytics: 0.3.3
firebase_remote_config: 0.0.2

sentry: 2.0.2

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down Expand Up @@ -57,6 +59,7 @@ flutter:
- images/main_empty_state.png
- images/arrow_bottom.png
- images/untappd.png
- images/default_beer.png

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
Expand All @@ -65,9 +68,6 @@ flutter:
# https://flutter.io/assets-and-images/#from-packages

fonts:
- family: beers
fonts:
- asset: fonts/beers.ttf
- family: Google Sans
fonts:
- asset: fonts/GoogleSans-Regular.ttf
Expand Down

0 comments on commit 504aa21

Please sign in to comment.