fix: Remove duplicate follow methods and fix FollowButton to use provider
This commit is contained in:
parent
70d4bc5140
commit
00b4705a00
|
|
@ -1062,22 +1062,6 @@ class ApiService {
|
||||||
// Social Actions
|
// Social Actions
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
Future<String?> followUser(String userId) async {
|
|
||||||
final data = await _callGoApi(
|
|
||||||
'/users/$userId/follow',
|
|
||||||
method: 'POST',
|
|
||||||
);
|
|
||||||
// Prefer explicit status, fallback to message if legacy
|
|
||||||
return (data['status'] as String?) ?? (data['message'] as String?);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> unfollowUser(String userId) async {
|
|
||||||
await _callGoApi(
|
|
||||||
'/users/$userId/follow',
|
|
||||||
method: 'DELETE',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<FollowRequest>> getFollowRequests() async {
|
Future<List<FollowRequest>> getFollowRequests() async {
|
||||||
final data = await _callGoApi('/users/requests');
|
final data = await _callGoApi('/users/requests');
|
||||||
final requests = data['requests'] as List<dynamic>? ?? [];
|
final requests = data['requests'] as List<dynamic>? ?? [];
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../services/api_service.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../providers/api_provider.dart';
|
||||||
import '../theme/app_theme.dart';
|
import '../theme/app_theme.dart';
|
||||||
|
|
||||||
/// Follow/Unfollow button with loading state and animations
|
/// Follow/Unfollow button with loading state and animations
|
||||||
class FollowButton extends StatefulWidget {
|
class FollowButton extends ConsumerStatefulWidget {
|
||||||
final String targetUserId;
|
final String targetUserId;
|
||||||
final bool initialIsFollowing;
|
final bool initialIsFollowing;
|
||||||
final Function(bool)? onFollowChanged;
|
final Function(bool)? onFollowChanged;
|
||||||
|
|
@ -18,10 +19,10 @@ class FollowButton extends StatefulWidget {
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FollowButton> createState() => _FollowButtonState();
|
ConsumerState<FollowButton> createState() => _FollowButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FollowButtonState extends State<FollowButton> {
|
class _FollowButtonState extends ConsumerState<FollowButton> {
|
||||||
late bool _isFollowing;
|
late bool _isFollowing;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
|
@ -45,7 +46,7 @@ class _FollowButtonState extends State<FollowButton> {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final api = ApiService();
|
final api = ref.read(apiServiceProvider);
|
||||||
if (_isFollowing) {
|
if (_isFollowing) {
|
||||||
await api.unfollowUser(widget.targetUserId);
|
await api.unfollowUser(widget.targetUserId);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,22 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.19.1"
|
version: "1.19.1"
|
||||||
|
connectivity_plus:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: connectivity_plus
|
||||||
|
sha256: b5e72753cf63becce2c61fd04dfe0f1c430cc5278b53a1342dc5ad839eab29ec
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.5"
|
||||||
|
connectivity_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_platform_interface
|
||||||
|
sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
convert:
|
convert:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -1253,6 +1269,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
|
nm:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: nm
|
||||||
|
sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.5.0"
|
||||||
node_preamble:
|
node_preamble:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <app_links/app_links_plugin_c_api.h>
|
#include <app_links/app_links_plugin_c_api.h>
|
||||||
|
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
|
||||||
#include <file_selector_windows/file_selector_windows.h>
|
#include <file_selector_windows/file_selector_windows.h>
|
||||||
#include <firebase_core/firebase_core_plugin_c_api.h>
|
#include <firebase_core/firebase_core_plugin_c_api.h>
|
||||||
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
||||||
|
|
@ -21,6 +22,8 @@
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
AppLinksPluginCApiRegisterWithRegistrar(
|
AppLinksPluginCApiRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
|
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
|
||||||
|
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
||||||
FileSelectorWindowsRegisterWithRegistrar(
|
FileSelectorWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("FileSelectorWindows"));
|
registry->GetRegistrarForPlugin("FileSelectorWindows"));
|
||||||
FirebaseCorePluginCApiRegisterWithRegistrar(
|
FirebaseCorePluginCApiRegisterWithRegistrar(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
app_links
|
app_links
|
||||||
|
connectivity_plus
|
||||||
file_selector_windows
|
file_selector_windows
|
||||||
firebase_core
|
firebase_core
|
||||||
flutter_inappwebview_windows
|
flutter_inappwebview_windows
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue