Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Favorite function #59

Merged
merged 33 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9b84d7c
setup for favorites
namelessto Jan 20, 2024
9e31192
basic func for favorites work
namelessto Jan 20, 2024
d027f12
WIP trying to change fav status on ui card
namelessto Jan 20, 2024
ce2c017
selecting towers to favorite consist after app is closed
namelessto Jan 21, 2024
7f752f6
generalized favorite state, towers and heroes added successfully
namelessto Jan 23, 2024
8fb8e08
better order of files
namelessto Jan 23, 2024
0f82d2f
moved bloons grids to separate files
namelessto Jan 23, 2024
275e3eb
favorites work now for towers heroes and bloons
namelessto Feb 8, 2024
4a97c36
now also bosses and maps work
namelessto Feb 8, 2024
1a3f68c
WIP orderable grid very basic functionality
namelessto Feb 8, 2024
efb48b6
WIP orderable grids show all categories
namelessto Feb 9, 2024
ef072d8
box saves updated order
namelessto Feb 9, 2024
a1ddd56
some cleanup
namelessto Feb 9, 2024
045da0a
navigation to favorites work now
namelessto Feb 9, 2024
171e5ea
fixed imports naming
namelessto Feb 9, 2024
55974d8
same
namelessto Feb 9, 2024
dbbcb43
added favorite button to single page
namelessto Feb 10, 2024
7b1bc13
added snack to all pages except favorite screen
namelessto Feb 10, 2024
9f9d7f1
added multi select for favorites
namelessto Feb 10, 2024
c8e1d20
moved toggleFavoriteFunc to state mgmt, added remove func to fav screen
namelessto Feb 10, 2024
d702467
import cleanup
namelessto Feb 10, 2024
10f84dc
add single remove func to fav screen and changed snackbar duration an…
namelessto Feb 10, 2024
230ae54
added favorites to layout presets
namelessto Feb 10, 2024
f9daacf
fixed bloons visuals for small screens
namelessto Feb 10, 2024
b284cdd
Update lib/presentation/screens/bloon/minion_bloon.dart
namelessto Feb 10, 2024
84cf3b6
fixed draggable cards and removed unnecessary field
namelessto Feb 10, 2024
84ac0fd
Merge branch 'favorite-func' of https://github.com/PlayfulSol/btd6-wi…
namelessto Feb 10, 2024
aa5226a
fixed import
namelessto Feb 10, 2024
9675b08
moved common widgets to common folder
namelessto Feb 10, 2024
5fe79e4
visual fixes for listtiles in main pages
namelessto Feb 10, 2024
fcaaffa
center
namelessto Feb 10, 2024
5c72d7b
added the d
namelessto Feb 10, 2024
ad584e1
updated version
namelessto Feb 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
2 changes: 2 additions & 0 deletions lib/analytics/analytics_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const String kHeroPagesClass = 'hero_pages';
const String kBloonPagesClass = 'bloon_pages';
const String kBossPagesClass = 'boss_pages';
const String kMapPagesClass = 'map_pages';
const String kFavoritesClass = 'favorites_page';

// ------- Const for event names -------
const String widgetEngagement = 'widget_engagement';
Expand Down Expand Up @@ -33,5 +34,6 @@ const String kHeroSkinsPage = 'hero_skins_page';
// ---- General ----
const String expansionTile = 'expansion_tile';
const String listTile = 'list_tile';
const String card = 'card';
const String buttonOpen = 'opened';
const String buttonClose = 'closed';
20 changes: 20 additions & 0 deletions lib/hive/favorite_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:hive_flutter/hive_flutter.dart';

part 'favorite_model.g.dart';

@HiveType(typeId: 1)
class FavoriteModel extends HiveObject {
@HiveField(0)
late final String id;

@HiveField(1)
late final String name;

@HiveField(2)
late final String image;

@HiveField(3)
late final String type;

FavoriteModel(this.id, this.name, this.image, this.type);
}
50 changes: 50 additions & 0 deletions lib/hive/favorite_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lib/hive/favorite_model_adapter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:hive_flutter/hive_flutter.dart';
import '/hive/favorite_model.dart';

class FavoriteModelBoxAdapter extends TypeAdapter<FavoriteModel> {
@override
final typeId = 1;

@override
FavoriteModel read(BinaryReader reader) {
return FavoriteModel(
// id
reader.readString(),
namelessto marked this conversation as resolved.
Show resolved Hide resolved
// name
reader.readString(),
// image
reader.readString(),
// type
reader.readString(),
);
}

@override
void write(BinaryWriter writer, FavoriteModel obj) {
writer.writeString(obj.id);
writer.writeString(obj.name);
writer.writeString(obj.image);
writer.writeString(obj.type);
}
}
132 changes: 92 additions & 40 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import '/firebase_options.dart';
import '/hive/favorite_model.dart';
import '/models/base/base_tower.dart';
import '/models/base/base_hero.dart';
import '/models/base/base_map.dart';
import '/models/base_model.dart';
import '/presentation/widgets/drawer_content.dart';
import '/presentation/screens/misc/favorite_screen.dart';
import '/presentation/widgets/misc/drawer_content.dart';
import '/presentation/screens/tower/towers.dart';
import '/presentation/screens/bloon/bloons.dart';
import '/presentation/screens/hero/heroes.dart';
import '/presentation/screens/maps/maps.dart';
import '/presentation/widgets/loader.dart';
import 'analytics/analytics_constants.dart';
import 'presentation/widgets/common/loader.dart';
import '/analytics/analytics_constants.dart';
import '/analytics/analytics.dart';
import '/utilities/favorite_state.dart';
import '/utilities/global_state.dart';
import '/utilities/constants.dart';
import '/utilities/requests.dart';
Expand All @@ -29,29 +33,43 @@ Future<void> main() async {
options: DefaultFirebaseOptions.currentPlatform,
);
final analytics = FirebaseAnalytics.instance;

await Hive.initFlutter();
Hive.registerAdapter(FavoriteModelAdapter());
await Hive.openBox<List<dynamic>>(
kFavorite,
keyComparator: desiredCategoryOrder,
);
runApp(MyApp(analytics: analytics));
}

class MyApp extends StatelessWidget {
const MyApp({super.key, required this.analytics});
final FirebaseAnalytics analytics;

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (BuildContext context) => GlobalState(),
return MultiProvider(
providers: [
ChangeNotifierProvider<GlobalState>(
create: (BuildContext context) => GlobalState(),
),
ChangeNotifierProvider<FavoriteState>(
create: (BuildContext context) => FavoriteState(),
),
],
child: AdaptiveTheme(
light: Themes.lightTheme,
dark: Themes.darkTheme,
initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => MaterialApp(
theme: theme,
darkTheme: darkTheme,
home: MyHomePage(
analytics: analytics,
),
debugShowCheckedModeBanner: false,
)),
light: Themes.lightTheme,
dark: Themes.darkTheme,
initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => MaterialApp(
theme: theme,
darkTheme: darkTheme,
home: MyHomePage(
analytics: analytics,
),
debugShowCheckedModeBanner: false,
),
),
);
}
}
Expand Down Expand Up @@ -152,30 +170,64 @@ class _MyHomePageState extends State<MyHomePage> {
: Container();
},
),
Consumer<GlobalState>(builder: (context, globalState, child) {
return IconButton(
onPressed: () {
globalState.switchSearch();
String value;
if (globalState.isSearchEnabled) {
value = searchOn;
} else {
globalState.updateCurrentQuery('');
value = searchOff;
}
analyticsHelper.logEvent(
name: widgetEngagement,
parameters: {
'screen': globalState.activeCategory,
'widget': searchButton,
'value': value,
Consumer<GlobalState>(
builder: (context, globalState, child) {
return IconButton(
onPressed: () {
globalState.switchSearch();
String value;
if (globalState.isSearchEnabled) {
value = searchOn;
} else {
globalState.updateCurrentQuery('');
value = searchOff;
}
analyticsHelper.logEvent(
name: widgetEngagement,
parameters: {
'screen': globalState.activeCategory,
'widget': searchButton,
'value': value,
},
);
},
icon: Icon(
!globalState.isSearchEnabled ? Icons.search : Icons.close),
);
},
),
Consumer<FavoriteState>(
builder: (context, favoriteState, child) {
IconData favIcon =
favoriteState.multiSelect ? Icons.add_task_sharp : Icons.star;
return GestureDetector(
onLongPress: () {
favoriteState.toggleMultiSelect();
},
child: IconButton(
onPressed: () {
if (!favoriteState.multiSelect) {
analyticsHelper.logScreenView(
screenClass: kFavoritesClass,
screenName: kFavoritesClass,
);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FavoriteScreen(
analyticsHelper: analyticsHelper,
),
),
);
} else {
favoriteState.toggleMultiSelect();
}
},
);
},
icon: Icon(
!globalState.isSearchEnabled ? Icons.search : Icons.close),
);
})
icon: Icon(favIcon),
),
);
},
),
],
),
body: !isLoading
Expand Down
Loading
Loading