Skip to content

Commit

Permalink
added snack to all pages except favorite screen
Browse files Browse the repository at this point in the history
  • Loading branch information
namelessto committed Feb 10, 2024
1 parent dbbcb43 commit 7b1bc13
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 67 deletions.
13 changes: 3 additions & 10 deletions lib/presentation/screens/bloon/boss_bloon.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:btd6wiki/utilities/favorite_state.dart';
import 'package:btd6wiki/utilities/utils.dart';
import 'package:provider/provider.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:carousel_slider/carousel_slider.dart';
Expand Down Expand Up @@ -67,16 +68,8 @@ class _BossBloonState extends State<BossBloon> {
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return IconButton(
onPressed: () {
String msg = favoriteState.toggleFavorite(boss);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: const Duration(milliseconds: 400),
),
);
},
onPressed: () =>
toggleFavoriteFunc(context, favoriteState, boss),
icon: favoriteState.isFavorite(boss.type, boss.id)
? const Icon(Icons.star)
: const Icon(Icons.star_border_outlined),
Expand Down
12 changes: 2 additions & 10 deletions lib/presentation/screens/bloon/single_bloon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,8 @@ class _SingleBloonState extends State<SingleBloon> {
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return IconButton(
onPressed: () {
String msg = favoriteState.toggleFavorite(bloon);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: const Duration(milliseconds: 400),
),
);
},
onPressed: () =>
toggleFavoriteFunc(context, favoriteState, bloon),
icon: favoriteState.isFavorite(bloon.type, bloon.id)
? const Icon(Icons.star)
: const Icon(Icons.star_border_outlined),
Expand Down
5 changes: 2 additions & 3 deletions lib/presentation/screens/hero/heroes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ class _HeroesState extends State<Heroes> {

return InkWell(
borderRadius: BorderRadius.circular(20),
onLongPress: () {
favoriteState.toggleFavorite(hero);
},
onLongPress: () =>
toggleFavoriteFunc(context, favoriteState, hero),
onTap: () {
widget.analyticsHelper.logEvent(
name: widgetEngagement,
Expand Down
12 changes: 2 additions & 10 deletions lib/presentation/screens/hero/single_hero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,8 @@ class _SingleHeroState extends State<SingleHero> {
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return IconButton(
onPressed: () {
String msg = favoriteState.toggleFavorite(singleHero);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: const Duration(milliseconds: 400),
),
);
},
onPressed: () => toggleFavoriteFunc(
context, favoriteState, singleHero),
icon: favoriteState.isFavorite(
singleHero.type, singleHero.id)
? const Icon(Icons.star)
Expand Down
5 changes: 2 additions & 3 deletions lib/presentation/screens/maps/maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ class _MapsState extends State<Maps> {
return Padding(
padding: const EdgeInsets.all(5.0),
child: GestureDetector(
onLongPress: () {
favoriteState.toggleFavorite(map);
},
onLongPress: () =>
toggleFavoriteFunc(context, favoriteState, map),
onTap: () {
widget.analyticsHelper.logEvent(
name: widgetEngagement,
Expand Down
15 changes: 4 additions & 11 deletions lib/presentation/screens/maps/single_map.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:btd6wiki/utilities/favorite_state.dart';
import 'package:btd6wiki/utilities/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -50,23 +51,15 @@ class _SingleMapState extends State<SingleMap> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: !loading
appBar: !loading
? AppBar(
title: Text(map.name),
actions: [
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return IconButton(
onPressed: () {
String msg = favoriteState.toggleFavorite(map);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: const Duration(milliseconds: 400),
),
);
},
onPressed: () =>
toggleFavoriteFunc(context, favoriteState, map),
icon: favoriteState.isFavorite(map.type, map.id)
? const Icon(Icons.star)
: const Icon(Icons.star_border_outlined),
Expand Down
12 changes: 2 additions & 10 deletions lib/presentation/screens/tower/single_tower.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,8 @@ class _SingleTowerState extends State<SingleTower> {
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return IconButton(
onPressed: () {
String msg = favoriteState.toggleFavorite(tower);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: const Duration(milliseconds: 400),
),
);
},
onPressed: () =>
toggleFavoriteFunc(context, favoriteState, tower),
icon: favoriteState.isFavorite(tower.type, tower.id)
? const Icon(Icons.star)
: const Icon(Icons.star_border_outlined),
Expand Down
6 changes: 2 additions & 4 deletions lib/presentation/screens/tower/towers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ class _TowersState extends State<Towers> {

return InkWell(
borderRadius: BorderRadius.circular(20),
onLongPress: () {
favoriteState.toggleFavorite(tower);
},
onLongPress: () =>
toggleFavoriteFunc(context, favoriteState, tower),
onTap: () {
widget.analyticsHelper.logEvent(
name: widgetEngagement,
Expand All @@ -88,7 +87,6 @@ class _TowersState extends State<Towers> {
towerId: tower.id,
analyticsHelper: widget.analyticsHelper,
),

),
);
},
Expand Down
6 changes: 3 additions & 3 deletions lib/presentation/widgets/bloons/bloons_grid.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:btd6wiki/utilities/utils.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '/models/base_model.dart';
Expand Down Expand Up @@ -37,9 +38,8 @@ class BloonsGrid extends StatelessWidget {
return Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return InkWell(
onLongPress: () {
favoriteState.toggleFavorite(bloon);
},
onLongPress: () =>
toggleFavoriteFunc(context, favoriteState, bloon),
onTap: () {
analyticsHelper.logEvent(
name: widgetEngagement,
Expand Down
6 changes: 3 additions & 3 deletions lib/presentation/widgets/bloons/bosses_grid.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:btd6wiki/utilities/utils.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import '/analytics/analytics_constants.dart';
Expand Down Expand Up @@ -36,9 +37,8 @@ class BossesGrid extends StatelessWidget {
return Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
return InkWell(
onLongPress: () {
favoriteState.toggleFavorite(boss);
},
onLongPress: () =>
toggleFavoriteFunc(context, favoriteState, boss),
onTap: () {
analyticsHelper.logEvent(
name: widgetEngagement,
Expand Down
2 changes: 2 additions & 0 deletions lib/utilities/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const int kMapsIndex = 3;

const String kFavorite = 'favorite';

const Duration snackBarDuration = Duration(milliseconds: 850);

const List<String> capTitles = [
'Towers',
'Heroes',
Expand Down
13 changes: 13 additions & 0 deletions lib/utilities/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:btd6wiki/utilities/favorite_state.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
import '/analytics/analytics_constants.dart';
Expand Down Expand Up @@ -95,6 +96,18 @@ void navigateToPage(BuildContext context, var item,
);
}

void toggleFavoriteFunc(
BuildContext context, FavoriteState favoriteState, var item) {
String msg = favoriteState.toggleFavorite(item);
ScaffoldMessenger.of(context).removeCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Center(child: Text(msg)),
duration: snackBarDuration,
),
);
}

String formatBigNumber(int number) {
if (number < 1000) {
return number.toString();
Expand Down

0 comments on commit 7b1bc13

Please sign in to comment.