Skip to content

Advanced

Setting user data

You can set user data by calling the setUserData function.

This function can be called from any screen from your app, just make sure to call it after the FeatureBuddyConfig.configure function.

This function takes an object with the following properties:

  • email: The user’s email.
  • userMeta: The user’s metadata. Can be any key-value pairs.
import 'package:featurebuddy/featurebuddy.dart';
void main() {
FeatureBuddyConfig.configure(apiKey: 'YOUR_API_KEY_GOES_HERE');
runApp(const MyApp());
}
Future<void> _setFakeUserData() async {
try {
await FeatureBuddyConfig.setUserData(
userMeta: {
'first_name': 'John',
'last_name': 'Doe',
'subscription_status': 'active',
},
);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('User data set successfully')),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error setting user data: $e')),
);
}
}
}