update: view remote code

This commit is contained in:
sanfan.hx
2019-08-15 13:59:08 +08:00
parent cdb06978d1
commit 927a99e62b
5 changed files with 95 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_go/utils/example_code_parser.dart'; import 'package:flutter_go/utils/example_code_parser.dart';
import 'package:flutter_go/utils/syntax_highlighter.dart'; import 'package:flutter_go/utils/syntax_highlighter.dart';
import 'package:flutter_go/utils/net_utils.dart';
class FullScreenCodeDialog extends StatefulWidget { class FullScreenCodeDialog extends StatefulWidget {
const FullScreenCodeDialog({this.filePath, this.remoteFilePath}); const FullScreenCodeDialog({this.filePath, this.remoteFilePath});
@ -22,17 +23,31 @@ class _FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
@override @override
void didChangeDependencies() { void didChangeDependencies() {
print('widget.filePath=======${widget.filePath}'); print('widget.filePath=======${widget.filePath}');
getExampleCode(context,'${widget.filePath}', DefaultAssetBundle.of(context)) if (widget.filePath != null) {
.then<void>((String code) { getExampleCode(context,'${widget.filePath}', DefaultAssetBundle.of(context))
if (mounted) { .then<void>((String code) {
setState(() { if (mounted) {
_exampleCode = code ?? 'Example code not found'; setState(() {
}); _exampleCode = code ?? 'Example code not found';
} });
}); }
});
}
if (widget.remoteFilePath != null) {
getRemotePathCode(widget.remoteFilePath);
}
super.didChangeDependencies(); super.didChangeDependencies();
} }
getRemotePathCode(path) async {
String response = await NetUtils.get(path);
if (mounted) {
setState(() {
_exampleCode = response ?? 'Example code not found';
});
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final SyntaxHighlighterStyle style = final SyntaxHighlighterStyle style =

View File

@ -79,7 +79,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
DataUtils.checkCollected(params).then((result) { DataUtils.checkCollected(params).then((result) {
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
_hasCollected = result; _hasCollected = result ?? null;
}); });
} }
}); });

View File

@ -59,6 +59,15 @@ var fullScreenCodeDialog = new Handler(
); );
}); });
var githubCodeDialog = new Handler(
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
String path = params['remotePath']?.first;
return new FullScreenCodeDialog(
remoteFilePath: path,
);
});
var webViewPageHand = new Handler( var webViewPageHand = new Handler(
handlerFunc: (BuildContext context, Map<String, List<String>> params) { handlerFunc: (BuildContext context, Map<String, List<String>> params) {
String title = params['title']?.first; String title = params['title']?.first;

View File

@ -30,6 +30,7 @@ class Routes {
router.define('/category/error/404', handler: widgetNotFoundHandler); router.define('/category/error/404', handler: widgetNotFoundHandler);
router.define(loginPage, handler: loginPageHandler); router.define(loginPage, handler: loginPageHandler);
router.define(codeView,handler:fullScreenCodeDialog); router.define(codeView,handler:fullScreenCodeDialog);
router.define(githubCodeView,handler:githubCodeDialog);
router.define(webViewPage,handler:webViewPageHand); router.define(webViewPage,handler:webViewPageHand);
router.define(issuesMessage, handler: issuesMessageHandler); router.define(issuesMessage, handler: issuesMessageHandler);
widgetDemosList.forEach((demo) { widgetDemosList.forEach((demo) {

View File

@ -15,12 +15,14 @@ import '../../components/flutter_markdown/lib/flutter_markdown.dart';
import '../../standard_pages/index.dart'; import '../../standard_pages/index.dart';
import '../../page_demo_package/index.dart'; import '../../page_demo_package/index.dart';
import 'package:flutter_go/routers/application.dart'; import 'package:flutter_go/routers/application.dart';
import 'package:flutter_go/routers/routers.dart';
import 'package:flutter_go/utils/net_utils.dart'; import 'package:flutter_go/utils/net_utils.dart';
import 'package:flutter_go/components/loading.dart'; import 'package:flutter_go/components/loading.dart';
const githubUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/standard_pages/'; const githubHost = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta';
const PagesUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/standard_pages/.pages.json'; const githubUrl = '$githubHost/lib/standard_pages/';
const DemosUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/page_demo_package/.demo.json'; const PagesUrl = '$githubHost/lib/standard_pages/.pages.json';
const DemosUrl = '$githubHost/lib/page_demo_package/.demo.json';
// ONLINE || LOCAL // ONLINE || LOCAL
@ -53,7 +55,7 @@ class _StandardView extends State<StandardView> {
Future<void> localGetPagesAttrsInfo() async { Future<void> localGetPagesAttrsInfo() async {
String jsonString = await DefaultAssetBundle.of(context).loadString('lib/standard_pages/.pages.json'); String jsonString = await DefaultAssetBundle.of(context).loadString('lib/standard_pages/.pages.json');
List jsonList = json.decode(jsonString); List jsonList = json.decode(jsonString);
Map<String, dynamic> pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id); Map<String, dynamic> pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id, orElse: null);
if (pageDetail != null) { if (pageDetail != null) {
setState(() { setState(() {
@ -69,12 +71,10 @@ class _StandardView extends State<StandardView> {
String pageId = widget.id; String pageId = widget.id;
Map<String, String> pagesList = standardPage.getPages(); Map<String, String> pagesList = standardPage.getPages();
print('pagesList[pageId]>>> ${pagesList[pageId]}'); // print('pagesList[pageId]>>> ${pagesList[pageId]}');
return pagesList[pageId]; return pagesList[pageId];
} }
Future<String> getContentOnline() async { Future<String> getContentOnline() async {
String content = 'online content';
this.setState(() { this.setState(() {
isLoading = true; isLoading = true;
}); });
@ -123,6 +123,24 @@ class _StandardView extends State<StandardView> {
} }
return Future(() => conent); return Future(() => conent);
} }
void seeSourceCode(id) async {
List response;
try {
response = jsonDecode(await NetUtils.get(DemosUrl));
} catch (e) {
return alertDialog(msg: '请检查网络链接', title: '提示');
}
Map<String, dynamic> demoDetail = response.firstWhere((item) => item['id'] == id, orElse: null);
if (demoDetail == null) {
return null;
}
String remoteSouceCode = '$githubHost/lib/page_demo_package/${demoDetail['name']}_${demoDetail['author']}_${demoDetail['id']}/src/index.dart';
Application.router.navigateTo(context,
'${Routes.githubCodeView}?remotePath=${Uri.encodeComponent(remoteSouceCode)}');
}
Widget buildFootInfo() { Widget buildFootInfo() {
if (!isLoading) { if (!isLoading) {
return Container( return Container(
@ -160,12 +178,45 @@ class _StandardView extends State<StandardView> {
String errString = "not found ${attrs['id']} in demo packages"; String errString = "not found ${attrs['id']} in demo packages";
debugPrint(errString); debugPrint(errString);
demo = [Text(errString)]; demo = [Text(errString)];
return Column(children: demo);
} else {
return Column(
children: <Widget>[
Column(
children: demo,
),
Divider(
color: Theme.of(context).primaryColor,
),
InkWell(
onTap: () {
seeSourceCode(attrs['id']);
},
child: Text("查看源码", style: TextStyle(color: Theme.of(context).primaryColor)),
)
],
) ;
} }
return Column(children: demo);
}); });
} }
alertDialog({String msg, String title}) {
showDialog<Null>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return new AlertDialog(
title: new Text(title),
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Text(msg),
],
),
)
);
},
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {