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

Feature/41 #35

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const String backendURL = "http://localhost:3000";
const String backendURLAndroid = "https://127.0.0.1:3000";
10 changes: 8 additions & 2 deletions lib/screen/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:flutter_svg/flutter_svg.dart';

import '../widgets/my_navigation_bar.dart';
import '../widgets/outlined_button.dart';
import '../models/user_model.dart';

class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key? key}) : super(key: key);
final UserModel userModel;
const ProfileScreen({Key? key, required this.userModel}) : super(key: key);

@override
State<ProfileScreen> createState() => _ProfileScreenState();
Expand All @@ -14,6 +16,7 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen>
with TickerProviderStateMixin {
late TabController _tabController;
late UserModel _userModel;

@override
void initState() {
Expand All @@ -22,6 +25,7 @@ class _ProfileScreenState extends State<ProfileScreen>
_tabController.addListener(() {
setState(() {});
});
_userModel = widget.userModel;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have another member variable here, using widget.userModel in the code is OK

}

@override
Expand Down Expand Up @@ -72,7 +76,9 @@ class _ProfileScreenState extends State<ProfileScreen>
height: 25,
),
Text(
"Will Rice College",
// once model matches with backend, fix this
_userModel.userName ?? "name_not_found",
// "bananalegend",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
Expand Down
69 changes: 64 additions & 5 deletions lib/widgets/post_widget.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:image_stack/image_stack.dart';
import 'package:rice_music_sharing/screen/profile_screen.dart';
import 'package:rice_music_sharing/widgets/post_action_button.dart';
import '../../constants.dart';
import 'package:http/http.dart' as http;
import '../models/user_model.dart';

class PostWidget extends StatelessWidget {
class PostWidget extends StatefulWidget {
// will take in a usermodel in the future
const PostWidget({Key? key}) : super(key: key);

@override
State<PostWidget> createState() => _PostWidget();
}

class _PostWidget extends State<PostWidget> {
late Future<UserModel> currUser;
String postUser = "bananalegend"; /* temporary username */

UserModel temp = UserModel(
netID: "jx29", displayName: "Vivian", userName: "Vivian", following: []);

void navigateToUser(BuildContext context) async {
currUser = fetchUser();
final user = await currUser;
// final user = temp;
// request user from backend
if (mounted) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProfileScreen(userModel: user)),
);
}
}

Future<UserModel> fetchUser() async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method should be moved out of Widget class for later usage

final response = await http.get(Uri.parse("$backendURL\\users\\$postUser"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason this uses \\ instead of /? The latter is more typical for paths, unless I'm missing something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Dio instead


if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
// decode the response to be a user model
return UserModel.fromJson(jsonDecode(response.body));
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load user');
}
}

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -25,10 +71,23 @@ class PostWidget extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const CircleAvatar(
backgroundImage:
NetworkImage("https://picsum.photos/250?image=9"),
radius: 18,
GestureDetector(
onTap: () {
navigateToUser(context);
},
child: Container(
width: 36.0,
height: 36.0,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://picsum.photos/250?image=9",
),
),
),
),
),
const SizedBox(
width: 10,
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_dotenv
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -242,6 +249,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.5"
http_multi_server:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies:
json_annotation: ^4.7.0
image_stack: ^2.1.1
flutter_svg: ^1.1.5
flutter_dotenv: ^5.0.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not using this dependency can we please remove it?

http: ^0.13.5

dev_dependencies:
flutter_test:
Expand Down