Skip to content

Commit

Permalink
Searching parties and users, API connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpiniasty committed Jul 7, 2023
1 parent b1fde50 commit e6df117
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 63 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ flutter pub get

## Example .env
```
URL = "http://127.0.0.1:8000"
URL = "http://0.0.0.0:8000"
```

## Running the App
Expand All @@ -24,7 +24,7 @@ flutter run
## Building and installing
In order to build the app run:
```
flutter build [apk / appbundle / ios] --release
flutter build [apk / appbundle / ios]
```

Once you've done that, run the following command:
Expand All @@ -36,6 +36,7 @@ flutter install

Drinkify uses [liquor-lovers](https://github.com/Kawaii-Addicts/liquor-lovers). Without it, app won't be able to work properly.


## Contributing

Contributions to Drinkify are always welcome and appreciated! If you would like to contribute, please fork this repository and submit a pull request with your changes.
Expand Down
1 change: 1 addition & 0 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PartyController {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/";
//TODO add party participants
final res = await http.post(
Uri.parse(url),
body: {
Expand Down
2 changes: 2 additions & 0 deletions lib/routes/create_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
}
}

//TODO use userLocation() from LocationUtils instead
///[selectLocation] must be true if you want to put marker on user's location after collecting coordinates
void _getUserLocation({bool selectLocation = false}) async {
bool serviceEnabled;
Expand Down Expand Up @@ -182,6 +183,7 @@ class _CreatePartyRouteState extends State<CreatePartyRoute> {
startTime: endTime!,
stopTime: endTime!,
privacyStatus: partyStatus,
participants: invitedUsers,
),
);
if (isCreated && mounted) {
Expand Down
36 changes: 27 additions & 9 deletions lib/routes/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import 'package:flutter/material.dart';

import '/utils/theming.dart';

import '../utils/theming.dart';
import '../widgets/homepage/welcome_header.dart';
import '../widgets/homepage/date_row.dart';
import '../widgets/homepage/party_list.dart';
import '../controllers/user_controller.dart';
import '../models/user.dart';

class HomePage extends StatelessWidget {
class HomePage extends StatefulWidget {
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
late User user;
@override
void initState() {
super.initState();
user = User.emptyUser();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final userData = await UserController.me();
setState(() => user = userData);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -17,19 +34,20 @@ class HomePage extends StatelessWidget {
padding: EdgeInsets.only(
top: MediaQuery.of(context).viewPadding.top + 20,
),
child: const Column(
child: Column(
children: [
//Had to use many paddings to make the DateRow boxes look better
Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: WelcomeHeader(),
padding: const EdgeInsets.symmetric(horizontal: 30),
child: WelcomeHeader(user),
),
DateRow(
textPadding: EdgeInsets.symmetric(horizontal: 30),
user,
textPadding: const EdgeInsets.symmetric(horizontal: 30),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: PartyList(),
padding: const EdgeInsets.symmetric(horizontal: 30),
child: PartyList(user),
),
],
),
Expand Down
6 changes: 4 additions & 2 deletions lib/widgets/homepage/date_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '/utils/ext.dart' show Capitalize;
import '/utils/theming.dart';

import '/models/user.dart';
import './date_picker.dart';

class DateRow extends StatefulWidget {
final User user;
final EdgeInsets textPadding;
const DateRow({
const DateRow(
this.user, {
required this.textPadding,
super.key,
});
Expand Down
7 changes: 6 additions & 1 deletion lib/widgets/homepage/party_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '/utils/theming.dart';
import '/models/user.dart';

class PartyList extends StatelessWidget {
const PartyList({super.key});
final User user;
const PartyList(
this.user, {
super.key,
});

@override
Widget build(BuildContext context) {
Expand Down
25 changes: 16 additions & 9 deletions lib/widgets/homepage/welcome_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '/utils/theming.dart';
import '/models/user.dart';

class WelcomeHeader extends StatelessWidget {
const WelcomeHeader({super.key});
final User user;
const WelcomeHeader(this.user, {super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -20,7 +22,7 @@ class WelcomeHeader extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${AppLocalizations.of(context)!.welcomeHeader}Oliwier',
'${AppLocalizations.of(context)!.welcomeHeader}${user.firstName ?? "..."}',
style: const TextStyle(
fontSize: 28,
color: Theming.whiteTone,
Expand All @@ -40,13 +42,18 @@ class WelcomeHeader extends StatelessWidget {
),
GestureDetector(
onTap: () => context.push("/settings"),
child: const CircleAvatar(
backgroundImage: NetworkImage(
"https://imgs.search.brave.com/Sh1KvzTzy10m30RShyompgGbNefsark8-QTMfC19svY/rs:fit:370:225:1/g:ce/aHR0cHM6Ly90c2Uz/Lm1tLmJpbmcubmV0/L3RoP2lkPU9JUC54/MWpmLWJTdGJlbkFo/U0poYXdKMmNRSGFK/ZSZwaWQ9QXBp",
),
backgroundColor: Theming.bgColorLight,
radius: 28,
),
child: user.pfp != null
? CircleAvatar(
radius: 28,
backgroundImage: NetworkImage(user.pfp!),
backgroundColor: Theming.bgColorLight,
)
: const CircleAvatar(
radius: 28,
backgroundImage:
AssetImage("assets/images/default_pfp.png"),
backgroundColor: Theming.bgColorLight,
),
),
],
),
Expand Down
28 changes: 25 additions & 3 deletions lib/widgets/partiespage/search_and_map.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:drinkify/widgets/glass_morphism.dart';
import 'package:flutter/material.dart' hide SearchController;
import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand All @@ -9,6 +8,7 @@ import '/controllers/search_controller.dart';
import '/models/party.dart';
import '/utils/ext.dart';
import '/models/search_type.dart';
import '/widgets/glass_morphism.dart';

class SearchAndMap extends StatefulWidget {
final Function(List<Party>) onPartySearch;
Expand Down Expand Up @@ -134,6 +134,9 @@ class _SearchAndMapState extends State<SearchAndMap> with LocationUtils {
cursorColor: Theming.primaryColor,
textAlign: TextAlign.center,
controller: searchCtrl,
keyboardType: searchType == SearchType.nearbyParties
? TextInputType.number
: TextInputType.name,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Theming.bgColor,
Expand All @@ -157,8 +160,26 @@ class _SearchAndMapState extends State<SearchAndMap> with LocationUtils {

//Seach button
GestureDetector(
onTap: () {
//TODO implement searching
onTap: () async {
switch (searchType) {
case SearchType.nearbyParties:
if (searchCtrl.text.isEmpty) return;
final coords = await userLocation();
if (coords == null) return;
final p = await SearchController.seachPartiesByDistance(
location: coords,
meters: double.parse(searchCtrl.text),
);
widget.onPartySearch(p);
return;
case SearchType.users:
if (searchCtrl.text.isEmpty) return;
final u = await SearchController.searchUser(
searchCtrl.text,
);
widget.onUserSearch(u);
return;
}
},
child: GlassMorphism(
blur: 0,
Expand Down Expand Up @@ -210,6 +231,7 @@ class _SearchAndMapState extends State<SearchAndMap> with LocationUtils {

return GestureDetector(
onTap: () {
searchCtrl.text = "";
setState(() {
selectedIndex = index;
searchType = type;
Expand Down
71 changes: 34 additions & 37 deletions lib/widgets/profilepage/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,44 +120,41 @@ class _UserInfoState extends State<UserInfo> {

const SizedBox(height: 10),

//Add friend / Social media link
Row(
children: [
//Add friend
GestureDetector(
onTap: () async {
//sending a friend request
const storage = FlutterSecureStorage();
final userId = await storage.read(key: "user_publicId");
if (widget.user!.publicId! == userId && mounted) {
showModalBottomSheet(
context: context,
builder: (ctx) {
return SuccessSheet(
success: false,
successMsg:
AppLocalizations.of(context)!.successFriendInvite,
failureMsg:
AppLocalizations.of(context)!.successFriendInvite,
);
});
}
},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width - 60,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theming.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Text(
AppLocalizations.of(context)!.addAFriend,
style: Styles.buttonTextLight,
),
),
//Add friend
GestureDetector(
onTap: () async {
//sending a friend request
const storage = FlutterSecureStorage();
final userId = await storage.read(key: "user_publicId");
if (widget.user!.publicId! == userId && mounted) {
showModalBottomSheet(
context: context,
useRootNavigator: true,
backgroundColor: Theming.bgColor,
builder: (ctx) {
return SuccessSheet(
success: false,
successMsg:
AppLocalizations.of(context)!.successFriendInvite,
failureMsg:
AppLocalizations.of(context)!.failureFriendInvite,
);
});
}
},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width - 60,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theming.primaryColor,
borderRadius: BorderRadius.circular(10),
),
],
child: Text(
AppLocalizations.of(context)!.addAFriend,
style: Styles.buttonTextLight,
),
),
),
],
);
Expand Down

0 comments on commit e6df117

Please sign in to comment.