У меня есть три направления слева, справа и вверх, в которых были реализованы различные функции, такие как неприязнь, такие как и суперподобные. Я хочу отключить карты от переворота в нижнем направлении, так как у меня нет функциональных возможностей для нисходящего направления. < /P>
key: ValueKey(_matches.length), // Use a unique key based on the list length
cards: List.generate(_matches.length, (index) {
final match = _matches[index];
final profile = match['profile'];
final userId = profile['id'];
return ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Stack(
fit: StackFit.expand,
alignment: Alignment.topCenter,
children: [
Image.network(
'$baseurl${profile['profile_picture']}',
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) => Image.asset(
'assets/default_profile_picture.png',
fit: BoxFit.cover,
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.7),
],
),
),
),
Positioned(
top: 16,
left: 16,
child: GestureDetector(
onTap: () async {
try {
final accessToken = await _getAccessToken();
if (accessToken == null) {
_showErrorSnackBar('Access token is missing');
return;
}
final response = await http.get(
Uri.parse('$baseurl/auth/unlocked-profiles/'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
},
);
if (response.statusCode == 200) {
final responseData = json.decode(response.body);
if (responseData.containsKey('profile_unlock_message') &&
responseData['profile_unlock_message'] ==
'Your plan does not allow profile unlocking.') {
await showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
alignment: Alignment.center,
children: [
ClipRRect(
borderRadius: const BorderRadius.vertical(top: Radius.circular(15)),
child: Image.asset(
'assets/profile_unlock.png',
height: 150,
width: double.infinity,
fit: BoxFit.cover,
),
),
Container(
height: 150,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.5),
],
),
),
),
Positioned(
bottom: 15,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
decoration: BoxDecoration(
color: Colors.pinkAccent,
borderRadius: BorderRadius.circular(20),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.lock_open,
color: Colors.white,
size: 18,
),
SizedBox(width: 6),
Text(
'PREMIUM FEATURE',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
],
),
),
),
],
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
const Text(
'Unlock Full Profiles',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 15),
const Text(
'To view complete profiles and connect with matches, you need an active subscription plan.',
style: TextStyle(
fontSize: 15,
color: Colors.grey,
height: 1.4,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 25),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.pinkAccent,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 0,
),
onPressed: () {
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddCreditsScreen(),
),
);
},
child: const Text(
'View Premium Plans',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text(
'Not Now',
style: TextStyle(
color: Colors.grey,
fontSize: 15,
),
),
),
],
),
),
],
),
),
);
},
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UserProfileScreen(
user: profile,
user1Id: _currentUserId,
user2Id: userId,
),
),
);
}
} else {
_showErrorSnackBar('Server error: ${response.statusCode}');
}
} catch (e) {
_showErrorSnackBar('Error checking profile: $e');
}
},
child: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.3),
shape: BoxShape.circle,
border: Border.all(
color: Colors.white.withOpacity(0.5),
width: 1,
),
),
child: const Icon(
Icons.person,
color: Colors.white,
size: 24,
),
),
),
),
Positioned(
bottom: 46,
left: 16,
right: 16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
profile['name'] ?? 'No Name',
style: GoogleFonts.dancingScript(
fontSize: 29,
color: Colors.white,
letterSpacing: 0.5,
shadows: [
Shadow(
blurRadius: 10.0,
color: Colors.black45,
offset: Offset(1.0, 1.0),
),
],
),
),
const SizedBox(height: 6),
Container(
width: double.infinity,
height: 2,
color: Colors.white30,
margin: const EdgeInsets.symmetric(vertical: 4),
),
Row(
children: [
Icon(
Icons.location_on_outlined,
color: Colors.white70,
size: 16,
),
const SizedBox(width: 4),
Text(
match['distance_km'] != null ? match['distance_km'].toString() : 'Location not specified',
style: TextStyle(
fontSize: 14,
color: const Color.fromARGB(179, 255, 255, 255),
fontStyle: profile['location'] == null ? FontStyle.italic : FontStyle.normal,
),
),
],
),
const SizedBox(height: 6),
Wrap(
spacing: 6,
children: (profile['interests'] as List?)
?.map((interestId) => Chip(
label: Text(
allInterests[interestId] ?? 'Unknown',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide.none,
),
))
.toList() ??
[],
),
],
),
),
],
),
);
}),
onSwipe: (int index, CardSwiperDirection direction) {
if (direction == CardSwiperDirection.bottom || direction.toString().toLowerCase().contains('down')) {
// Just return without doing anything to ignore downward swipes
return;
}
if (_matches.isEmpty) {
print('No more matches available'); // Debug print
return;
}
setState(() {
_isSwipingLeft = direction == CardSwiperDirection.left;
_isSwipingRight = direction == CardSwiperDirection.right;
});
final match = _matches.first; // Get the first match
final profile = match['profile'];
final userId = profile['id']; // Extract profile.id from the current match
print('Extracted userId: $userId'); // Debug print to check if userId is correct
// Remove the card from the list immediately after swiping
setState(() {
if (_matches.isNotEmpty) {
_matches.removeAt(0); // Remove the first match
}
});
if (direction == CardSwiperDirection.right) {
Fluttertoast.showToast(msg: '
handleSwipe(
swipeType: 'like',
swipedOnId: userId, // Pass the extracted userId directly
);
} else if (direction == CardSwiperDirection.left) {
Fluttertoast.showToast(msg: '
handleSwipe(
swipeType: 'dislike',
swipedOnId: userId, // Pass the extracted userId directly
);
} else if (direction == CardSwiperDirection.top) {
handleSwipe(swipeType: 'superlike', swipedOnId: userId).then((response) {
if (response != null && response.statusCode == 200) {
// Show a popup indicating superlike
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Superlike!'),
content: Text('You have superliked ${profile['name']}'),
actions: [
TextButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} else if (response != null && response.statusCode == 403) {
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.symmetric(horizontal: 20),
child: Container(
decoration: BoxDecoration(
color: Color(0xFF1A1A1A),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.purple.withOpacity(0.2),
blurRadius: 15,
spreadRadius: 1,
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
child: Stack(
alignment: Alignment.center,
children: [
Image.asset(
'assets/subscription.png',
height: 160,
width: double.infinity,
fit: BoxFit.cover,
),
Container(
height: 160,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.7),
],
),
),
),
Positioned(
bottom: 10,
child: Icon(
Icons.lock,
color: Colors.white,
size: 32,
),
),
],
),
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
Text(
'Premium Access Required',
style: TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
SizedBox(height: 16),
Text(
'You need a subscription to access this feature. Upgrade to unlock all premium benefits.',
style: TextStyle(
color: Colors.grey[400],
fontSize: 16,
),
textAlign: TextAlign.center,
),
SizedBox(height: 24),
Row(
children: [
Expanded(
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.grey[400],
),
child: Text(
'Not Now',
style: TextStyle(fontSize: 16),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple[600],
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Text(
'Get Premium',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
Navigator.of(context).pop();
// Navigate to subscription page or show subscription options
// Example: Navigator.push(context, MaterialPageRoute(builder: (context) => SubscriptionPage()));
},
),
),
],
),
],
),
),
],
),
),
);
},
);
} else {
// Handle other status codes if necessary
print('Swipe action failed. Status: ${response?.statusCode}');
}
});
}
// Delay to hide the swipe indicators after a short time
Future.delayed(Duration(milliseconds: 300), () {
setState(() {
_isSwipingLeft = false;
_isSwipingRight = false;
});
});
},
),`
Подробнее здесь: https://stackoverflow.com/questions/795 ... ttom-direc
Мобильная версия