-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: develop
Are you sure you want to change the base?
Feature/41 #35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"; |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason this uses There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
@@ -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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
There was a problem hiding this comment.
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