refactor:code view

This commit is contained in:
yifeng.yl
2019-01-14 17:15:15 +08:00
parent 5da3b4c3e9
commit 441ed56a00
15 changed files with 125 additions and 144 deletions

View File

@ -2,15 +2,17 @@
* @Author: 一凨
* @Date: 2019-01-14 11:42:36
* @Last Modified by: 一凨
* @Last Modified time: 2019-01-14 15:53:20
* @Last Modified time: 2019-01-14 16:53:11
*/
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import '../routers/application.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';
const String _kStartTag = '// START ';
const String _kEndTag = '// END';
@ -18,47 +20,27 @@ const String _kEndTag = '// END';
Map<String, String> _exampleCode;
String _code;
Future<String> getExampleCode(String filePath, AssetBundle bundle) async {
if (_exampleCode == null)
await _parseExampleCode(filePath,bundle);
// return _exampleCode[filePath];
void _launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Future<String> getExampleCode(context,String filePath, AssetBundle bundle) async {
if (_exampleCode == null) await _parseExampleCode(context,filePath, bundle);
return _code;
}
Future<void> _parseExampleCode(String filePath,AssetBundle bundle) async {
final String code = await bundle.loadString('$filePath') ??
'// $filePath not found\n';
print('$filePath 1234567Nealyang');
_code = code;
// _exampleCode = <String, String>{};
// final List<String> lines = code.split('\n');
// List<String> codeBlock;
// String codeTag;
// for (String line in lines) {
// if (codeBlock == null) {
// // Outside a block.
// if (line.startsWith(_kStartTag)) {
// // Starting a new code block.
// codeBlock = <String>[];
// codeTag = line.substring(_kStartTag.length).trim();
// } else {
// // Just skipping the line.
// }
// } else {
// // Inside a block.
// if (line.startsWith(_kEndTag)) {
// // Add the block.
// _exampleCode[codeTag] = codeBlock.join('\n');
// codeBlock = null;
// codeTag = null;
// } else {
// // Add to the current block
// // trimRight() to remove any \r on Windows
// // without removing any useful indentation
// codeBlock.add(line.trimRight());
// }
// }
// }
Future<void> _parseExampleCode(context,String filePath, AssetBundle bundle) async {
String code;
try {
code = await bundle.loadString('lib/widgets/$filePath');
} catch (err) {
print('${Application.github['widgetsURL']} $filePath');
Navigator.of(context).pop();
_launchURL(Application.github['widgetsURL'] + filePath);
}
_code = code;
}