Skip to content

Commit 4b0863d

Browse files
committed
feat:环境切换
1 parent 57c6336 commit 4b0863d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/components/widget_comp.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ class IndexState extends State<Index> {
116116
);
117117
}
118118

119+
showCode(context) async {
120+
if (Store.value<ConfigModel>(context).isPro) {
121+
// 线上文档
122+
FluroRouter.router.navigateTo(
123+
context,
124+
'webview?title=${widget.title}&url=${Uri.encodeComponent(Store.value<ConfigModel>(context).env.githubAssetOrigin+widget.mdUrl)}'
125+
);
126+
} else {
127+
// 加载本地
128+
String mdStr = await AssetUtils.readLocaleFile(widget.mdUrl);
129+
Navigator.of(context).push(
130+
MaterialPageRoute(builder: (BuildContext build) {
131+
return Scaffold(
132+
appBar: AppBar(title: Text(widget.title),),
133+
body: ListView(
134+
children: <Widget>[markdown_comp.Index(mdStr)],
135+
),
136+
);
137+
})
138+
);
139+
}
140+
}
141+
119142
Future getMdFile(url) async {
120143
// bool productionEnv = Store.value<ConfigModel>(context).isPro;
121144
bool productionEnv = false;
@@ -128,6 +151,15 @@ class IndexState extends State<Index> {
128151

129152
getActions(context) {
130153
return [
154+
IconButton(
155+
color: Color(AppTheme.blackColor),
156+
icon: Icon(
157+
Icons.code
158+
),
159+
onPressed: () async {
160+
this.showCode(context);
161+
},
162+
),
131163
IconButton(
132164
color: Color(AppTheme.blackColor),
133165
icon: Icon(

lib/page/mine/index.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ class _IndexState extends State<Index> {
111111
Divider(
112112
color: Color(AppTheme.lineColor),
113113
),
114+
ListTile(
115+
onTap: () {
116+
Store.value<ConfigModel>(context).$setIsPro();
117+
},
118+
leading: Icon(Icons.verified_user),
119+
title: Text(
120+
Store.value<ConfigModel>(context).isPro ? '线上环境' : '本地环境'
121+
),
122+
),
123+
Divider(
124+
color: Color(AppTheme.lineColor),
125+
),
114126
(Platform.isAndroid)
115127
? ListTile(
116128
onTap: () {

lib/store/models/config_state_model.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ class ConfigModel extends ConfigInfo with ChangeNotifier {
3232
notifyListeners();
3333
}
3434

35+
Future $setIsPro() async {
36+
isPro = !isPro;
37+
notifyListeners();
38+
}
39+
3540
}

0 commit comments

Comments
 (0)