Skip to content

Commit

Permalink
Merge pull request #35 from NonLegit/developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
ahmedmadbouly186 authored Dec 10, 2022
2 parents b351de4 + 01bb706 commit 2f7bf12
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 69 deletions.
18 changes: 9 additions & 9 deletions lib/moderated_subreddit/models/moderated_subreddit_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class ModeratedSubredditData {
required this.moderators});

ModeratedSubredditData.fromJson(Map<String, dynamic> json) {
print(json);
print(json['_id'].runtimeType);
print(json['fixedName'].runtimeType);
print(json['name'].runtimeType);
print(json['description'].runtimeType);
// print(json['subredditLink'].runtimeType);
print(json['isJoined'].runtimeType);
print(json['rules'].runtimeType);
print(json['moderators'].runtimeType);
// print(json);
// print(json['_id'].runtimeType);
// print(json['fixedName'].runtimeType);
// print(json['name'].runtimeType);
// print(json['description'].runtimeType);
// // print(json['subredditLink'].runtimeType);
// print(json['isJoined'].runtimeType);
// print(json['rules'].runtimeType);
// print(json['moderators'].runtimeType);
id = json['_id'];
name = json['fixedName'];
displayName = json['name'];
Expand Down
2 changes: 1 addition & 1 deletion lib/myprofile/screens/myprofile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:provider/provider.dart';
import '../../widgets/loading_reddit.dart';
import '../widgets/myprofile_web.dart';
import '../widgets/myProfile_app.dart';
import '../widgets/myprofile_app.dart';
import '../models/myprofile_data.dart';
import '../providers/myprofile_provider.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/networks/dio_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DioClient {
print('hi');
print(token);
} catch (error) {
print(error);
print('dio error $error');
}
dio = Dio(
BaseOptions(
Expand All @@ -41,7 +41,7 @@ class DioClient {
{required String path,
Map<String, dynamic>? data,
Map<String, dynamic>? query}) async {
print(data);
print('eror in dio post : $data');
return await dio!.post(path, data: json.encode(data));
}

Expand Down
9 changes: 4 additions & 5 deletions lib/other_profile/models/moderated_subreddit_user_data.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class ModeratedSubbredditUserData {
String? icon;
String ?subredditName;
String? icon;
String? subredditName;
ModeratedSubbredditUserData(
{required this.icon, required this.subredditName});


ModeratedSubbredditUserData.fromJson(Map<String, dynamic> json) {
icon = json['id'].toString();
subredditName = json['userName'].toString();
icon = json['icon'].toString();
subredditName = json['fixedName'].toString();
}
}
54 changes: 33 additions & 21 deletions lib/other_profile/providers/other_profile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import '../models/others_profile_data.dart';
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/moderated_subreddit_user_data.dart';

//using in heighest widget to use
class OtherProfileprovider with ChangeNotifier {
OtherProfileData? loadProfile;
List< ModeratedSubbredditUserData> ?moderatedSubbredditUserData;
List<ModeratedSubbredditUserData>? moderatedSubbredditUserData;
OtherProfileData? get gettingOtherProfileData {
return loadProfile;
}
List< ModeratedSubbredditUserData> ? get gettingModeratedSubreddit{
return moderatedSubbredditUserData;
}

List<ModeratedSubbredditUserData>? get gettingModeratedSubreddit {
return moderatedSubbredditUserData;
}

Future<void> fetchAndSetOtherProfile(String otherUserName) async {
try {
final prefs = await SharedPreferences.getInstance();
Expand All @@ -25,8 +28,8 @@ class OtherProfileprovider with ChangeNotifier {
// print(userName);
await DioClient.get(path: '/users/${otherUserName}/about')
.then((response) {
print(response.data['data']);
loadProfile = OtherProfileData.fromJson(response.data['data']);
print(response.data['user']);
loadProfile = OtherProfileData.fromJson(response.data['user']);
notifyListeners();
});
} catch (error) {
Expand All @@ -36,53 +39,62 @@ class OtherProfileprovider with ChangeNotifier {
}
}

Future<void> fetchAndSetModeratedSubredditUser() async {
Future<void> fetchAndSetModeratedSubredditUser() async {
try {
final prefs = await SharedPreferences.getInstance();
DioClient.init(prefs);

print('12ssdsadsadsada ');
await DioClient.get(
path: '/subreddits/mine/moderator',
).then((response) {
print(response.data);
path: '/subreddits/mine/moderator',
).then((response) {
print('erorrr ${response.statusCode}');
print(response);
List<ModeratedSubbredditUserData> tempData = [];
response.data['subreddits'].forEach((subreedit) {
response.data['data'].forEach((subreedit) {
tempData.add(ModeratedSubbredditUserData.fromJson(subreedit));
});
moderatedSubbredditUserData = tempData;
notifyListeners();
});
} catch (error) {
// print('12 ');
// print('heelo');
print(error);
print('heelo');
throw (error);
}
}
Future<bool> invitation(String subredditUserName, String moderatorName) async {

Future<bool> invitation(
String subredditUserName, String moderatorName) async {
try {
final prefs = await SharedPreferences.getInstance();
final prefs = await SharedPreferences.getInstance();
print(prefs);
DioClient.init(prefs);
await DioClient.post(path:'/subreddits/${subredditName}/moderators/${moderatorName}',
);
await DioClient.post(
path: '/subreddits/${subredditName}/moderators/${moderatorName}',
).then((value) => print(value));
notifyListeners();
return true;
} catch (error) {
print('error in invitaion : $error');
return false;
}
}

Future<bool> blockUser(String userName) async {
try {
final prefs = await SharedPreferences.getInstance();
final prefs = await SharedPreferences.getInstance();
print(prefs);
print(userName);
DioClient.init(prefs);
await DioClient.post(path:'/users/${userName}/block_user',
);
await DioClient.post(
path: '/users/${userName}/block_user',
);
notifyListeners();
return true;
} catch (error) {
print('blocked error $error');
return false;
}
}
}

61 changes: 32 additions & 29 deletions lib/other_profile/widgets/invite_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ class InviteButton extends StatefulWidget {
}

class InviteButtonState extends State<InviteButton> {
List<ModeratedSubbredditUserData>? subdata = [
ModeratedSubbredditUserData(
icon:
'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
subredditName: 'reddit'),
ModeratedSubbredditUserData(
icon:
'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
subredditName: 'reddit'),
ModeratedSubbredditUserData(
icon:
'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
subredditName: 'reddit')
];
List<ModeratedSubbredditUserData>? subdata
// = [
// ModeratedSubbredditUserData(
// icon:
// 'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
// subredditName: 'reddit'),
// ModeratedSubbredditUserData(
// icon:
// 'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
// subredditName: 'reddit'),
// ModeratedSubbredditUserData(
// icon:
// 'https://www.redditstatic.com/notifications/default_subreddit_avatar.png',
// subredditName: 'reddit')
// ];
;
String textMessage = '';
late String subredditName;
late TextEditingController message;
Expand All @@ -47,21 +49,22 @@ class InviteButtonState extends State<InviteButton> {
void didChangeDependencies() {
// TODO: implement didChangeDependencies
//===============================doing fetch=======================================//
// if (_isInit) {
// setState(() {
// _isLoading = true;
// });
// Provider.of<OtherProfileprovider>(context, listen: false)
// .fetchAndSetModeratedSubredditUser()
// .then((value) {
// subdata = Provider.of<OtherProfileprovider>(context, listen: false)
// .gettingModeratedSubreddit;
// setState(() {
// _isLoading = false;
// });
// });
// }
// _isInit = false;
if (_isInit) {
setState(() {
_isLoading = true;
});
// print('12 ');
Provider.of<OtherProfileprovider>(context, listen: false)
.fetchAndSetModeratedSubredditUser()
.then((value) {
subdata = Provider.of<OtherProfileprovider>(context, listen: false)
.gettingModeratedSubreddit;
setState(() {
_isLoading = false;
});
});
}
_isInit = false;

//==================================================//
super.didChangeDependencies();
Expand Down
2 changes: 0 additions & 2 deletions lib/settings/screens/blocked_accounts.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:responsive_sizer/responsive_sizer.dart';
import '../widgets/icon_list_view.dart';
Expand Down

0 comments on commit 2f7bf12

Please sign in to comment.