Skip to main content
This guide will walk you through implementing session management in your Flutter app using the Dynamic Flutter SDK. You’ll learn how to manage authentication state, handle reactive UI updates with Streams, and create a seamless user experience.

Overview

Session management is a crucial part of any Web3 app. The Dynamic Flutter SDK provides powerful Stream-based reactive state management for user sessions, authentication state, and wallet updates. This guide covers the practical implementation patterns you’ll need to build a robust session management system.

Key Concepts

Reactive State with Streams

The SDK provides Dart Streams that automatically emit updates when state changes:
  • authenticatedUserChanges - Emits when user logs in or out
  • tokenChanges - Emits when the auth token changes
  • userWalletsChanges - Emits when wallets are created or updated
  • readyChanges - Emits when SDK initialization state changes

Automatic UI Updates

By subscribing to these streams in your Flutter widgets using StreamBuilder, the UI automatically updates when:
  • Users log in or out
  • Authentication tokens refresh
  • Wallets are connected or created
  • SDK ready state changes

Implementation Patterns

1. Basic Session Management

Start with a simple session management setup:

2. Advanced Session State Management

For more complex apps, create a dedicated session manager:

3. Using Session Manager with Provider

Listening to Specific State Changes

Authentication Token Changes

User Profile Changes

Wallet Changes

SDK Ready State

Session Persistence

The Dynamic SDK automatically persists sessions across app restarts. When your app launches:
  1. Initialize the SDK in main()
  2. Wait for readyChanges to emit true
  3. Check tokenChanges or authenticatedUserChanges for existing session
  4. If a valid session exists, the user is automatically authenticated

Manual Session Check

You can manually check the current session state:

Logout

To end a user’s session:

Best Practices

1. Always Use StreamBuilders

Use StreamBuilder widgets to automatically update UI when session state changes:

2. Include Dynamic Widget Overlay

Always include DynamicSDK.instance.dynamicWidget in your widget tree:

3. Wait for SDK Ready

Always check that the SDK is ready before using it:

4. Dispose Subscriptions

If manually subscribing to streams, always cancel subscriptions:

Troubleshooting

Session Not Persisting

  • Ensure SDK is initialized in main() before runApp()
  • Check that DynamicSDK.instance.dynamicWidget is included in widget tree
  • Verify you’re not clearing app data or cache between sessions

UI Not Updating

  • Make sure you’re using StreamBuilder to listen to state changes
  • Check that streams are being subscribed to correctly
  • Verify the widget tree is being rebuilt when state changes

Token Expired

The SDK automatically handles token refresh. If you see authentication failures:
  • Check network connectivity
  • Verify your environment ID is correct
  • Check dashboard settings for session duration

What’s Next

Now that you understand session management:
  1. Wallet Creation - Learn about automatic wallet creation after authentication
  2. Go Router Integration - Integrate session management with go_router navigation
  3. Token Balances - Display and manage wallet balances
  4. SDK Reference - Explore the complete SDK API

Reference

For more details on session management APIs, see:
Last modified on February 3, 2026