|
| 1 | +import 'package:app/presentation/resources/resources.dart'; |
| 2 | +import 'package:app/presentation/themes/local_theme.dart'; |
| 3 | +import 'package:domain/env/env_config.dart'; |
| 4 | +import 'package:domain/services/environment_service.dart'; |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | + |
| 7 | +import '../../../main/init.dart'; |
| 8 | + |
| 9 | +class EnvironmentSelector extends StatelessWidget { |
| 10 | + EnvironmentSelector({ |
| 11 | + super.key, |
| 12 | + }); |
| 13 | + |
| 14 | + final EnvironmentService environmentService = getIt<EnvironmentService>(); |
| 15 | + |
| 16 | + DropdownMenuItem<String> _item( |
| 17 | + String value, String label, TextStyle textStyle) => |
| 18 | + DropdownMenuItem<String>( |
| 19 | + value: value, |
| 20 | + child: Padding( |
| 21 | + padding: EdgeInsets.symmetric(horizontal: spacing.xs), |
| 22 | + child: Text(label, style: textStyle), |
| 23 | + ), |
| 24 | + ); |
| 25 | + |
| 26 | + @override |
| 27 | + Widget build(BuildContext context) { |
| 28 | + final textStyle = |
| 29 | + Theme.of(context).textTheme.bodyLarge?.copyWith(color: Theme.of(context).colorScheme.primary.v0); |
| 30 | + |
| 31 | + final items = <DropdownMenuItem<String>>[ |
| 32 | + _item(EnvConfig.kDevEnv, 'Development', textStyle!), |
| 33 | + _item(EnvConfig.kQaEnv, 'QA', textStyle), |
| 34 | + _item(EnvConfig.kProdEnv, 'Production', textStyle), |
| 35 | + ]; |
| 36 | + |
| 37 | + return DropdownButtonFormField<String>( |
| 38 | + initialValue: EnvConfig.env, |
| 39 | + style: textStyle, |
| 40 | + decoration: InputDecoration( |
| 41 | + labelText: 'Environment', |
| 42 | + border: const OutlineInputBorder(), |
| 43 | + prefixIcon: const Icon(Icons.settings), |
| 44 | + labelStyle: textStyle, |
| 45 | + ), |
| 46 | + items: items, |
| 47 | + onChanged: (value) => environmentService.setEnvironment(value!), |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
0 commit comments