Configuration
After creating your new FLEX application with flexcli new example_app, you’ll need to configure several key components to get your Mobile App up and running. This guide covers the essential configuration steps using SAP Starter Kit as an example with Contentful powering the CMS.
Environment Configuration
Section titled “Environment Configuration”1. Setting Up Environment Variables
Section titled “1. Setting Up Environment Variables”Your project includes an example.env file that needs to be configured with your specific credentials and endpoints. Copy this file to .env and fill in the required values:
cp example.env .envSAP Configuration
Section titled “SAP Configuration”Configure your SAP Commerce Cloud connection:
SAP_CLIENT_ID=your_sap_client_idSAP_CLIENT_SECRET=your_sap_client_secretSAP_BASE_URL=https://your-sap-instance.comRequired for:
- User authentication
- Product catalog access
- Cart and order management
- Search functionality
Contentful CMS Configuration
Section titled “Contentful CMS Configuration”Set up your Contentful CMS integration:
CONTENTFUL_ENVIRONMENT=masterCONTENTFUL_SPACE_ID=your_space_idCONTENTFUL_DELIVERY_API_TOKEN=your_delivery_tokenCONTENTFUL_PREVIEW_API_TOKEN=your_preview_tokenCONTENTFUL_MANAGEMENT_API_TOKEN=your_management_tokenCONTENTFUL_HOST=cdn.contentful.comToken Purposes:
- Delivery API Token: For published content in production
- Preview API Token: For unpublished/draft content during development
- Management API Token: For content management operations (optional)
2. Loading Environment Variables
Section titled “2. Loading Environment Variables”The application automatically loads environment variables during startup:
await dotenv.load();final String kCmsFeatureApiKey = dotenv.get('CONTENTFUL_DELIVERY_API_TOKEN');Internationalization (i18n) Configuration
Section titled “Internationalization (i18n) Configuration”Supported Locales
Section titled “Supported Locales”Configure the languages and regions your app supports by modifying the I18nFeature initialization in main.dart:
I18nFeature( supportedLocales: [ const Locale('en', 'CA'), // English (Canada) const Locale('en', 'US'), // English (United States) const Locale('fr', 'CA'), // French (Canada) const Locale('es', 'MX'), // Spanish (Mexico) ], defaultLocale: const Locale('en', 'CA'),),Adding New Locales
Section titled “Adding New Locales”To add support for additional languages:
- Add the locale to the
supportedLocalesarray - Create corresponding translation files in your
assets/i18n/directory - Update your
pubspec.yamlto include the new translation assets
Changing Default Locale
Section titled “Changing Default Locale”Update the defaultLocale parameter to set your preferred default language:
defaultLocale: const Locale('en', 'US'), // Change to your preferred defaultApplication Navigation Configuration
Section titled “Application Navigation Configuration”Root Page and Bottom Navigation
Section titled “Root Page and Bottom Navigation”The starter kit includes a bottom navigation structure defined in root_page.dart. This file controls the main navigation tabs of your application.
Common customizations:
- Add or remove navigation tabs
- Change tab icons and labels
- Modify the navigation flow
- Customize the bottom navigation bar appearance
To customize the navigation structure, locate and modify the root_page.dart file in your project structure.
FLEX Core Features Configuration
Section titled “FLEX Core Features Configuration”Logging Configuration
Section titled “Logging Configuration”The application includes comprehensive logging setup:
LoggingFeature( config: const FlexLoggerConfig( minLevel: kDebugMode ? LogLevel.debug : LogLevel.info, showEmojis: true, showTimestamp: true, showSource: true, useShortName: true, enableColors: true, ),),Configuration Options:
minLevel: Set logging verbosity (debug, info, warning, error)showEmojis: Enable emoji indicators in logsshowTimestamp: Include timestamps in log entriesshowSource: Show the source of each log entryuseShortName: Use abbreviated logger namesenableColors: Enable colored console output
CMS Feature Configuration
Section titled “CMS Feature Configuration”Configure content management system integration:
CMSFeature( provider: ContentfulProvider(apiKey: kCmsFeatureApiKey), enableDebugLogging: true, // Set to false in production),Network Configuration
Section titled “Network Configuration”For development environments with self-signed certificates, the starter kit includes certificate bypass logic:
class MyHttpOverrides extends HttpOverrides { @override HttpClient createHttpClient(SecurityContext? context) { return super.createHttpClient(context) ..badCertificateCallback = (X509Certificate cert, String host, int port) => true; }}Important: Remove or modify this for production deployments to maintain security.
Development vs Production Configuration
Section titled “Development vs Production Configuration”Debug Mode Settings
Section titled “Debug Mode Settings”Several configurations automatically adjust based on the build mode:
// Logging verbosityminLevel: kDebugMode ? LogLevel.debug : LogLevel.info,
// CMS debug loggingenableDebugLogging: kDebugMode, // Enable only in debug buildsNext Steps
Section titled “Next Steps”After completing the basic configuration:
- Test Integration: Verify SAP Commerce and Contentful CMS connectivity
- Customize the UI: Configure FLEX UI theme design tokens and sizes
- Add Features: Extend the starter kit with additional FLEX features
- Customize Navigation: Modify the bottom navigation to match your app structure
Troubleshooting
Section titled “Troubleshooting”Common Configuration Issues
Section titled “Common Configuration Issues”Environment Variables Not Loading:
- Ensure
.envfile is in the project root - Verify file name (not
example.env) - Check that
flutter_dotenvis properly configured
SAP Connection Issues:
- Verify SAP credentials and base URL
- Check network connectivity
- Review certificate configuration for HTTPS endpoints
Contentful CMS Issues:
- Validate API tokens and space ID
- Ensure content models are published
- Check environment configuration (master vs. development)
Locale Issues:
- Verify translation files exist for all supported locales
- Check
pubspec.yamlasset configuration - Ensure locale codes follow ISO standards