debug_environment_view.dart
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../../core/config/app_environment.dart';
import '../../../../core/config/app_environment_config.dart';
import '../../../../core/constants/app_const.dart';
import '../../../../core/network/dio_client.dart';
import '../../../../core/util/app_toast.dart';
class DebugEnvironmentView extends StatelessWidget {
const DebugEnvironmentView({super.key});
static const _brandColor = Color(0xFF845EEE);
static const _titleColor = Color(0xFF0F0F11);
@override
Widget build(BuildContext context) {
final environmentConfig = Get.find<AppEnvironmentConfig>();
final dioClient = Get.find<DioClient>();
return Scaffold(
backgroundColor: const Color(0xFFF7F6FA),
appBar: AppBar(
title: const Text('Debug'),
centerTitle: true,
backgroundColor: Colors.white,
foregroundColor: _titleColor,
elevation: 0,
),
body: SafeArea(
child: Obx(() {
final current = environmentConfig.environment.value;
return ListView(
padding: const EdgeInsets.all(16),
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: Column(
children: [
for (final environment in AppEnvironment.values)
RadioListTile<AppEnvironment>(
value: environment,
groupValue: current,
activeColor: _brandColor,
title: Text(
environment.debugName,
style: const TextStyle(
color: _titleColor,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
subtitle: Text(
environmentConfig.resolveServerUrlFor(
environment,
AppConst.serverBaseUrl,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
onChanged: (value) async {
if (value == null || value == current) return;
await environmentConfig.setEnvironment(value);
dioClient.refreshBaseUrl();
AppToast.show(
'环境已切换: ${environmentConfig.serverBaseUrl}',
);
},
),
],
),
),
],
);
}),
),
);
}
}
extension on AppEnvironment {
String get debugName {
return switch (this) {
AppEnvironment.dev => 'Dev',
AppEnvironment.xlab => 'XLab',
AppEnvironment.release => 'Release',
};
}
}