mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-21 23:06:33 +08:00
modified : add code view
This commit is contained in:
64
lib/common/example_code_parser.dart
Normal file
64
lib/common/example_code_parser.dart
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* @Author: 一凨
|
||||||
|
* @Date: 2019-01-14 11:42:36
|
||||||
|
* @Last Modified by: 一凨
|
||||||
|
* @Last Modified time: 2019-01-14 15:53:20
|
||||||
|
*/
|
||||||
|
// 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 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
const String _kStartTag = '// START ';
|
||||||
|
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];
|
||||||
|
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());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
73
lib/common/full_screen_code_dialog.dart
Normal file
73
lib/common/full_screen_code_dialog.dart
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* @Author: 一凨
|
||||||
|
* @Date: 2019-01-14 11:42:32
|
||||||
|
* @Last Modified by: 一凨
|
||||||
|
* @Last Modified time: 2019-01-14 14:42:00
|
||||||
|
*/
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'example_code_parser.dart';
|
||||||
|
import 'syntax_highlighter.dart';
|
||||||
|
|
||||||
|
class FullScreenCodeDialog extends StatefulWidget {
|
||||||
|
const FullScreenCodeDialog({this.filePath});
|
||||||
|
|
||||||
|
final String filePath;
|
||||||
|
_FullScreenCodeDialogState createState() => _FullScreenCodeDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
|
||||||
|
String _exampleCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
getExampleCode(widget.filePath, DefaultAssetBundle.of(context))
|
||||||
|
.then<void>((String code) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_exampleCode = code ?? 'Example code not found';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super.didChangeDependencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final SyntaxHighlighterStyle style =
|
||||||
|
Theme.of(context).brightness == Brightness.dark
|
||||||
|
? SyntaxHighlighterStyle.darkThemeStyle()
|
||||||
|
: SyntaxHighlighterStyle.lightThemeStyle();
|
||||||
|
|
||||||
|
Widget body;
|
||||||
|
if (_exampleCode == null) {
|
||||||
|
body = const Center(child: CircularProgressIndicator());
|
||||||
|
} else {
|
||||||
|
body = SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: RichText(
|
||||||
|
text: TextSpan(
|
||||||
|
style: const TextStyle(fontFamily: 'monospace', fontSize: 10.0),
|
||||||
|
children: <TextSpan>[
|
||||||
|
DartSyntaxHighlighter(style).format(_exampleCode)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.clear,
|
||||||
|
semanticLabel: 'Close',
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
title: const Text('Example code'),
|
||||||
|
),
|
||||||
|
body: body);
|
||||||
|
}
|
||||||
|
}
|
362
lib/common/syntax_highlighter.dart
Normal file
362
lib/common/syntax_highlighter.dart
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
/*
|
||||||
|
* @Author: 一凨
|
||||||
|
* @Date: 2019-01-14 11:42:39
|
||||||
|
* @Last Modified by: 一凨
|
||||||
|
* @Last Modified time: 2019-01-14 11:42:39
|
||||||
|
*/
|
||||||
|
// 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 'package:flutter/material.dart';
|
||||||
|
import 'package:string_scanner/string_scanner.dart';
|
||||||
|
|
||||||
|
class SyntaxHighlighterStyle {
|
||||||
|
SyntaxHighlighterStyle({
|
||||||
|
this.baseStyle,
|
||||||
|
this.numberStyle,
|
||||||
|
this.commentStyle,
|
||||||
|
this.keywordStyle,
|
||||||
|
this.stringStyle,
|
||||||
|
this.punctuationStyle,
|
||||||
|
this.classStyle,
|
||||||
|
this.constantStyle
|
||||||
|
});
|
||||||
|
|
||||||
|
static SyntaxHighlighterStyle lightThemeStyle() {
|
||||||
|
return SyntaxHighlighterStyle(
|
||||||
|
baseStyle: const TextStyle(color: Color(0xFF000000)),
|
||||||
|
numberStyle: const TextStyle(color: Color(0xFF1565C0)),
|
||||||
|
commentStyle: const TextStyle(color: Color(0xFF9E9E9E)),
|
||||||
|
keywordStyle: const TextStyle(color: Color(0xFF9C27B0)),
|
||||||
|
stringStyle: const TextStyle(color: Color(0xFF43A047)),
|
||||||
|
punctuationStyle: const TextStyle(color: Color(0xFF000000)),
|
||||||
|
classStyle: const TextStyle(color: Color(0xFF512DA8)),
|
||||||
|
constantStyle: const TextStyle(color: Color(0xFF795548))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SyntaxHighlighterStyle darkThemeStyle() {
|
||||||
|
return SyntaxHighlighterStyle(
|
||||||
|
baseStyle: const TextStyle(color: Color(0xFFFFFFFF)),
|
||||||
|
numberStyle: const TextStyle(color: Color(0xFF1565C0)),
|
||||||
|
commentStyle: const TextStyle(color: Color(0xFF9E9E9E)),
|
||||||
|
keywordStyle: const TextStyle(color: Color(0xFF80CBC4)),
|
||||||
|
stringStyle: const TextStyle(color: Color(0xFF009688)),
|
||||||
|
punctuationStyle: const TextStyle(color: Color(0xFFFFFFFF)),
|
||||||
|
classStyle: const TextStyle(color: Color(0xFF009688)),
|
||||||
|
constantStyle: const TextStyle(color: Color(0xFF795548))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final TextStyle baseStyle;
|
||||||
|
final TextStyle numberStyle;
|
||||||
|
final TextStyle commentStyle;
|
||||||
|
final TextStyle keywordStyle;
|
||||||
|
final TextStyle stringStyle;
|
||||||
|
final TextStyle punctuationStyle;
|
||||||
|
final TextStyle classStyle;
|
||||||
|
final TextStyle constantStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SyntaxHighlighter { // ignore: one_member_abstracts
|
||||||
|
TextSpan format(String src);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DartSyntaxHighlighter extends SyntaxHighlighter {
|
||||||
|
DartSyntaxHighlighter([this._style]) {
|
||||||
|
_spans = <_HighlightSpan>[];
|
||||||
|
_style ??= SyntaxHighlighterStyle.darkThemeStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
SyntaxHighlighterStyle _style;
|
||||||
|
|
||||||
|
static const List<String> _keywords = <String>[
|
||||||
|
'abstract', 'as', 'assert', 'async', 'await', 'break', 'case', 'catch',
|
||||||
|
'class', 'const', 'continue', 'default', 'deferred', 'do', 'dynamic', 'else',
|
||||||
|
'enum', 'export', 'external', 'extends', 'factory', 'false', 'final',
|
||||||
|
'finally', 'for', 'get', 'if', 'implements', 'import', 'in', 'is', 'library',
|
||||||
|
'new', 'null', 'operator', 'part', 'rethrow', 'return', 'set', 'static',
|
||||||
|
'super', 'switch', 'sync', 'this', 'throw', 'true', 'try', 'typedef', 'var',
|
||||||
|
'void', 'while', 'with', 'yield'
|
||||||
|
];
|
||||||
|
|
||||||
|
static const List<String> _builtInTypes = <String>[
|
||||||
|
'int', 'double', 'num', 'bool'
|
||||||
|
];
|
||||||
|
|
||||||
|
String _src;
|
||||||
|
StringScanner _scanner;
|
||||||
|
|
||||||
|
List<_HighlightSpan> _spans;
|
||||||
|
|
||||||
|
@override
|
||||||
|
TextSpan format(String src) {
|
||||||
|
_src = src;
|
||||||
|
_scanner = StringScanner(_src);
|
||||||
|
|
||||||
|
if (_generateSpans()) {
|
||||||
|
// Successfully parsed the code
|
||||||
|
final List<TextSpan> formattedText = <TextSpan>[];
|
||||||
|
int currentPosition = 0;
|
||||||
|
|
||||||
|
for (_HighlightSpan span in _spans) {
|
||||||
|
if (currentPosition != span.start)
|
||||||
|
formattedText.add(TextSpan(text: _src.substring(currentPosition, span.start)));
|
||||||
|
|
||||||
|
formattedText.add(TextSpan(style: span.textStyle(_style), text: span.textForSpan(_src)));
|
||||||
|
|
||||||
|
currentPosition = span.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPosition != _src.length)
|
||||||
|
formattedText.add(TextSpan(text: _src.substring(currentPosition, _src.length)));
|
||||||
|
|
||||||
|
return TextSpan(style: _style.baseStyle, children: formattedText);
|
||||||
|
} else {
|
||||||
|
// Parsing failed, return with only basic formatting
|
||||||
|
return TextSpan(style: _style.baseStyle, text: src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _generateSpans() {
|
||||||
|
int lastLoopPosition = _scanner.position;
|
||||||
|
|
||||||
|
while (!_scanner.isDone) {
|
||||||
|
// Skip White space
|
||||||
|
_scanner.scan(RegExp(r'\s+'));
|
||||||
|
|
||||||
|
// Block comments
|
||||||
|
if (_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.comment,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line comments
|
||||||
|
if (_scanner.scan('//')) {
|
||||||
|
final int startComment = _scanner.lastMatch.start;
|
||||||
|
|
||||||
|
bool eof = false;
|
||||||
|
int endComment;
|
||||||
|
if (_scanner.scan(RegExp(r'.*\n'))) {
|
||||||
|
endComment = _scanner.lastMatch.end - 1;
|
||||||
|
} else {
|
||||||
|
eof = true;
|
||||||
|
endComment = _src.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.comment,
|
||||||
|
startComment,
|
||||||
|
endComment
|
||||||
|
));
|
||||||
|
|
||||||
|
if (eof)
|
||||||
|
break;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw r"String"
|
||||||
|
if (_scanner.scan(RegExp(r'r".*"'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw r'String'
|
||||||
|
if (_scanner.scan(RegExp(r"r'.*'"))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiline """String"""
|
||||||
|
if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiline '''String'''
|
||||||
|
if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "String"
|
||||||
|
if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'String'
|
||||||
|
if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.string,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double
|
||||||
|
if (_scanner.scan(RegExp(r'\d+\.\d+'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.number,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integer
|
||||||
|
if (_scanner.scan(RegExp(r'\d+'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.number,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end)
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Punctuation
|
||||||
|
if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.punctuation,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Meta data
|
||||||
|
if (_scanner.scan(RegExp(r'@\w+'))) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
_HighlightType.keyword,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Words
|
||||||
|
if (_scanner.scan(RegExp(r'\w+'))) {
|
||||||
|
_HighlightType type;
|
||||||
|
|
||||||
|
String word = _scanner.lastMatch[0];
|
||||||
|
if (word.startsWith('_'))
|
||||||
|
word = word.substring(1);
|
||||||
|
|
||||||
|
if (_keywords.contains(word))
|
||||||
|
type = _HighlightType.keyword;
|
||||||
|
else if (_builtInTypes.contains(word))
|
||||||
|
type = _HighlightType.keyword;
|
||||||
|
else if (_firstLetterIsUpperCase(word))
|
||||||
|
type = _HighlightType.klass;
|
||||||
|
else if (word.length >= 2 && word.startsWith('k') && _firstLetterIsUpperCase(word.substring(1)))
|
||||||
|
type = _HighlightType.constant;
|
||||||
|
|
||||||
|
if (type != null) {
|
||||||
|
_spans.add(_HighlightSpan(
|
||||||
|
type,
|
||||||
|
_scanner.lastMatch.start,
|
||||||
|
_scanner.lastMatch.end
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this loop did anything
|
||||||
|
if (lastLoopPosition == _scanner.position) {
|
||||||
|
// Failed to parse this file, abort gracefully
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
lastLoopPosition = _scanner.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
_simplify();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _simplify() {
|
||||||
|
for (int i = _spans.length - 2; i >= 0; i -= 1) {
|
||||||
|
if (_spans[i].type == _spans[i + 1].type && _spans[i].end == _spans[i + 1].start) {
|
||||||
|
_spans[i] = _HighlightSpan(
|
||||||
|
_spans[i].type,
|
||||||
|
_spans[i].start,
|
||||||
|
_spans[i + 1].end
|
||||||
|
);
|
||||||
|
_spans.removeAt(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _firstLetterIsUpperCase(String str) {
|
||||||
|
if (str.isNotEmpty) {
|
||||||
|
final String first = str.substring(0, 1);
|
||||||
|
return first == first.toUpperCase();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum _HighlightType {
|
||||||
|
number,
|
||||||
|
comment,
|
||||||
|
keyword,
|
||||||
|
string,
|
||||||
|
punctuation,
|
||||||
|
klass,
|
||||||
|
constant
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HighlightSpan {
|
||||||
|
_HighlightSpan(this.type, this.start, this.end);
|
||||||
|
final _HighlightType type;
|
||||||
|
final int start;
|
||||||
|
final int end;
|
||||||
|
|
||||||
|
String textForSpan(String src) {
|
||||||
|
return src.substring(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextStyle textStyle(SyntaxHighlighterStyle style) {
|
||||||
|
if (type == _HighlightType.number)
|
||||||
|
return style.numberStyle;
|
||||||
|
else if (type == _HighlightType.comment)
|
||||||
|
return style.commentStyle;
|
||||||
|
else if (type == _HighlightType.keyword)
|
||||||
|
return style.keywordStyle;
|
||||||
|
else if (type == _HighlightType.string)
|
||||||
|
return style.stringStyle;
|
||||||
|
else if (type == _HighlightType.punctuation)
|
||||||
|
return style.punctuationStyle;
|
||||||
|
else if (type == _HighlightType.klass)
|
||||||
|
return style.classStyle;
|
||||||
|
else if (type == _HighlightType.constant)
|
||||||
|
return style.constantStyle;
|
||||||
|
else
|
||||||
|
return style.baseStyle;
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,10 @@ import '../widgets/index.dart';
|
|||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import '../event/event-bus.dart';
|
import '../event/event-bus.dart';
|
||||||
import '../event/event-model.dart';
|
import '../event/event-model.dart';
|
||||||
|
import './full_screen_code_dialog.dart';
|
||||||
|
import '../routers/application.dart';
|
||||||
|
import '../routers/routers.dart';
|
||||||
|
import 'dart:core';
|
||||||
|
|
||||||
class WidgetDemo extends StatefulWidget {
|
class WidgetDemo extends StatefulWidget {
|
||||||
final List<dynamic> contentList;
|
final List<dynamic> contentList;
|
||||||
@ -141,7 +145,10 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
|||||||
if(value == 'doc'){
|
if(value == 'doc'){
|
||||||
_launchURL(widget.docUrl);
|
_launchURL(widget.docUrl);
|
||||||
}else if(value =='code'){
|
}else if(value =='code'){
|
||||||
_launchURL(Application.github['widgetsURL'] + widget.codeUrl);
|
// _launchURL(Application.github['widgetsURL'] + widget.codeUrl);
|
||||||
|
String targetUrl = 'lib/widgets/${widget.codeUrl}';
|
||||||
|
Application.router.navigateTo(context, '${Routes.codeView}?filePath=${Uri.encodeComponent(targetUrl)}');
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
_getCollection();
|
_getCollection();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
import '../views/category.dart';
|
import '../views/category.dart';
|
||||||
import '../widgets/404.dart';
|
import '../widgets/404.dart';
|
||||||
|
import '../common/full_screen_code_dialog.dart';
|
||||||
|
|
||||||
var categoryHandler = new Handler(
|
var categoryHandler = new Handler(
|
||||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
|
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
|
||||||
@ -16,3 +17,10 @@ var widgetNotFoundHandler = new Handler(
|
|||||||
return new WidgetNotFound();
|
return new WidgetNotFound();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var fullScreenCodeDialog = new Handler(
|
||||||
|
handlerFunc: (BuildContext context,Map<String, List<String>> params){
|
||||||
|
String path = params['filePath']?.first;
|
||||||
|
return new FullScreenCodeDialog(filePath: path,);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -7,6 +7,7 @@ import './router_handler.dart';
|
|||||||
class Routes {
|
class Routes {
|
||||||
static String root = "/";
|
static String root = "/";
|
||||||
static String widgetDemo = '/widget-demo';
|
static String widgetDemo = '/widget-demo';
|
||||||
|
static String codeView = '/code-view';
|
||||||
|
|
||||||
static void configureRoutes(Router router) {
|
static void configureRoutes(Router router) {
|
||||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
List widgetDemosList = new WidgetDemoList().getDemos();
|
||||||
@ -17,13 +18,12 @@ class Routes {
|
|||||||
|
|
||||||
router.define('/category/:type', handler: categoryHandler);
|
router.define('/category/:type', handler: categoryHandler);
|
||||||
router.define('/category/error/404', handler: widgetNotFoundHandler);
|
router.define('/category/error/404', handler: widgetNotFoundHandler);
|
||||||
|
router.define(codeView,handler:fullScreenCodeDialog);
|
||||||
widgetDemosList.forEach((demo) {
|
widgetDemosList.forEach((demo) {
|
||||||
Handler handler = new Handler(
|
Handler handler = new Handler(
|
||||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
|
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
|
||||||
return demo.buildRouter(context);
|
return demo.buildRouter(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
router.define('${demo.routerName}', handler: handler);
|
router.define('${demo.routerName}', handler: handler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* 基本示例
|
* 基本示例
|
||||||
* */
|
*
|
||||||
|
*/
|
||||||
class DefaultTextField extends StatelessWidget {
|
class DefaultTextField extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
120
pubspec.yaml
120
pubspec.yaml
@ -45,8 +45,128 @@ flutter:
|
|||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
|
- lib/widgets/elements/Form/Input/TextField/text_field_demo.dart
|
||||||
|
- lib/widgets/elements/Form/CheckBox/Checkbox/demo.dart
|
||||||
|
- lib/widgets/components/Bar/AppBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/BottomAppBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/ButtonBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/FlexibleSpaceBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/SliverAppBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/SnackBar/demo.dart
|
||||||
|
- lib/widgets/components/Bar/SnackBarAction/demo.dart
|
||||||
|
- lib/widgets/components/Bar/TabBar/demo.dart
|
||||||
|
- lib/widgets/components/Card/Card/demo.dart
|
||||||
|
- lib/widgets/components/Chip/Chip/demo.dart
|
||||||
|
- lib/widgets/components/Chip/ChipTheme/demo.dart
|
||||||
|
- lib/widgets/components/Chip/ChipThemeData/demo.dart
|
||||||
|
- lib/widgets/components/Chip/ChoiceChip/demo.dart
|
||||||
|
- lib/widgets/components/Chip/FilterChip/demo.dart
|
||||||
|
- lib/widgets/components/Chip/inputChip/demo.dart
|
||||||
|
- lib/widgets/components/Chip/RawChip/demo.dart
|
||||||
|
- lib/widgets/components/Dialog/AboutDialog/demo.dart
|
||||||
|
- lib/widgets/components/Dialog/AlertDialog/demo.dart
|
||||||
|
- lib/widgets/components/Dialog/Dialog/demo.dart
|
||||||
|
- lib/widgets/components/Dialog/SimpleDialog/demo.dart
|
||||||
|
- lib/widgets/components/Grid/GridTile/demo.dart
|
||||||
|
- lib/widgets/components/Grid/GridTileBar/demo.dart
|
||||||
|
- lib/widgets/components/Grid/GridView/demo.dart
|
||||||
|
- lib/widgets/components/LIst/AnimatedList/demo.dart
|
||||||
|
- lib/widgets/components/LIst/ListBody/demo.dart
|
||||||
|
- lib/widgets/components/LIst/ListView/demo.dart
|
||||||
|
- lib/widgets/components/Menu/CheckedPopupMenuItem/demo.dart
|
||||||
|
- lib/widgets/components/Menu/DropdownMenuItem/demo.dart
|
||||||
|
- lib/widgets/components/Menu/PopupMenuButton/demo.dart
|
||||||
|
- lib/widgets/components/Menu/PopupMenuDivider/demo.dart
|
||||||
|
- lib/widgets/components/Navigation/BottomNavigationBar/demo.dart
|
||||||
|
- lib/widgets/components/Navigation/BottomNavigationBarItem/demo.dart
|
||||||
|
- lib/widgets/components/Panel/ExpansionPanel/demo.dart
|
||||||
|
- lib/widgets/components/Panel/ExpansionPanelList/demo.dart
|
||||||
|
- lib/widgets/components/Pick/DayPicker/demo.dart
|
||||||
|
- lib/widgets/components/Pick/MonthPicker/demo.dart
|
||||||
|
- lib/widgets/components/Pick/ShowdatePicker/demo.dart
|
||||||
|
- lib/widgets/components/Pick/YearPicker/demo.dart
|
||||||
|
- lib/widgets/components/Progress/CircularProgressIndicator/demo.dart
|
||||||
|
- lib/widgets/components/Progress/LinearProgressIndicator/demo.dart
|
||||||
|
- lib/widgets/components/Progress/RefreshProgressIndicator/demo.dart
|
||||||
|
- lib/widgets/components/Scaffold/Scaffold/demo.dart
|
||||||
|
- lib/widgets/components/Scaffold/ScaffoldState/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/BoxScrollView/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/CustomScrollView/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/NestedScrollView/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/Scrollable/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/ScrollbarPainter/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/ScrollMetrics/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/ScrollPhysics/demo.dart
|
||||||
|
- lib/widgets/components/Scroll/ScrollView/demo.dart
|
||||||
|
- lib/widgets/components/Tab/Tab/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/DropdownButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/FlatButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/FloatingActionButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/IconButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/OutlineButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/PopupMenuButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/RaisedButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Button/RawMaterialButton/demo.dart
|
||||||
|
- lib/widgets/elements/Form/CheckBox/Checkbox/demo.dart
|
||||||
|
- lib/widgets/elements/Form/CheckBox/CheckboxListTile/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Radio/Radio/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Radio/RadioListTile/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Slider/Slider/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Slider/SliderTheme/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Slider/SliderThemeData/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Switch/AnimatedSwitcher/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Switch/Switch/demo.dart
|
||||||
|
- lib/widgets/elements/Form/Switch/SwitchListTile/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Align/Align/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/ConstrainedBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/DecoratedBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/Fittedbox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/LimitedBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/OverflowBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/RenderBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/RotatedBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/SizeBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/SizedOverflowBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/TextBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Box/UnconstrainedBox/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Expanded/Expanded/expanded_demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Layout/Center/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Layout/Column/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Layout/Container/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Layout/Row/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Spacing/AnimatedPadding/animatedPadding_demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Spacing/Padding/padding_demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Spacing/SliverPadding/sliverpadding_demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Stack/IndexedStack/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Stack/Stack/demo.dart
|
||||||
|
- lib/widgets/elements/Frame/Table/Table/table_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Icon/Icon/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Icon/IconData/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Icon/IconTheme/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Icon/IconThemeData/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Icon/ImageIcon/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/AssetImage/assetImage_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/DecorationImage/decorationImage_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/DecorationImagePainter/decoration_image_painter_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/ExactAssetImage/exact_asset_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/FadeInImage/fade_in_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/FileImage/file_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/Image/demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/MemoryImage/memory_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/NetworkImage/network_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/paintImage/paint_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/precacheImage/precache_image_demo.dart
|
||||||
|
- lib/widgets/elements/Media/Image/RawImage/raw_image_demo.dart
|
||||||
|
- lib/widgets/themes/Material/MaterialApp/demo.dart
|
||||||
|
- lib/widgets/themes/Material/MaterialButton/demo.dart
|
||||||
|
- lib/widgets/themes/Material/MaterialColor/demo.dart
|
||||||
|
- lib/widgets/themes/Material/MaterialPageRoute/demo.dart
|
||||||
|
- lib/widgets/themes/Material/MergeableMaterialItem/demo.dart
|
||||||
- assets/app.db
|
- assets/app.db
|
||||||
- assets/images/
|
- assets/images/
|
||||||
|
- lib/common/example_code_parser.dart
|
||||||
|
- lib/common/syntax_highlighter.dart
|
||||||
|
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
|
Reference in New Issue
Block a user