mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-23 15:56:25 +08:00
refactor:code view
This commit is contained in:
@ -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');
|
||||
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;
|
||||
// _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());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class _FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
getExampleCode(widget.filePath, DefaultAssetBundle.of(context))
|
||||
getExampleCode(context,'${widget.filePath}', DefaultAssetBundle.of(context))
|
||||
.then<void>((String code) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
@ -146,8 +146,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
||||
_launchURL(widget.docUrl);
|
||||
}else if(value =='code'){
|
||||
// _launchURL(Application.github['widgetsURL'] + widget.codeUrl);
|
||||
String targetUrl = 'lib/widgets/${widget.codeUrl}';
|
||||
Application.router.navigateTo(context, '${Routes.codeView}?filePath=${Uri.encodeComponent(targetUrl)}');
|
||||
Application.router.navigateTo(context, '${Routes.codeView}?filePath=${Uri.encodeComponent(widget.codeUrl)}');
|
||||
|
||||
}else{
|
||||
_getCollection();
|
||||
|
@ -1,9 +1,10 @@
|
||||
/*
|
||||
* @Author: xiaojia.dxj
|
||||
* @Date: 2018-12-18 11:40:57
|
||||
* @Last Modified by: xiaojia.dxj
|
||||
* @Last Modified time: 2018-12-20 15:03:18
|
||||
* @Last Modified by: 一凨
|
||||
* @Last Modified time: 2019-01-14 16:50:43
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ChipDemo extends StatefulWidget {
|
||||
@ -11,13 +12,12 @@ class ChipDemo extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ChipDemoState extends State<ChipDemo> {
|
||||
String dec='点击回收';
|
||||
int count=0;
|
||||
_modifty(){
|
||||
String dec = '点击回收';
|
||||
int count = 0;
|
||||
_modifty() {
|
||||
setState(() {
|
||||
dec='delete success: $count';
|
||||
dec = 'delete success: $count';
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
@ -26,42 +26,53 @@ class _ChipDemoState extends State<ChipDemo> {
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: Chip(
|
||||
padding: EdgeInsets.only(right: 100.0,),
|
||||
padding: EdgeInsets.only(
|
||||
right: 100.0,
|
||||
),
|
||||
//标签前面的小widget
|
||||
avatar: CircleAvatar(
|
||||
backgroundColor: Colors.red.shade200,
|
||||
child: Text('A',style: TextStyle(color: Colors.white),),
|
||||
|
||||
child: Text(
|
||||
'A',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
label: Text(
|
||||
'pai mai ',
|
||||
style: TextStyle(color: Colors.white, fontSize: 18.0),
|
||||
),
|
||||
label: Text('pai mai ',style: TextStyle(color: Colors.white,fontSize: 18.0),),
|
||||
backgroundColor: Colors.red.shade100,
|
||||
labelPadding: EdgeInsets.all(6.0),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
|
||||
height: 100.0,
|
||||
child: Chip(
|
||||
//头像
|
||||
avatar: CircleAvatar(
|
||||
child: Icon(Icons.account_circle,color: Colors.red.shade200,),
|
||||
backgroundColor:Colors.white,
|
||||
|
||||
child: Icon(
|
||||
Icons.account_circle,
|
||||
color: Colors.red.shade200,
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
),
|
||||
//设置widget背景颜色
|
||||
backgroundColor: Colors.red.shade100,
|
||||
/**剪辑窗口widget内容
|
||||
* antiAlias:剪辑具有抗锯齿功能,它比antiAliasWithSaveLayer快得多,但比hardEdge慢。
|
||||
antiAliasWithSaveLayer:立即剪辑具有抗锯齿,并且可以分配屏幕外缓冲区,后续涂料都在该缓冲区完成,然后再进行修剪和合成
|
||||
*/
|
||||
//剪辑窗口widget内容
|
||||
// antiAlias:剪辑具有抗锯齿功能,它比antiAliasWithSaveLayer快得多,但比hardEdge慢。
|
||||
//antiAliasWithSaveLayer:立即剪辑具有抗锯齿,并且可以分配屏幕外缓冲区,后续涂料都在该缓冲区完成,然后再进行修剪和合成
|
||||
clipBehavior: Clip.antiAlias,
|
||||
|
||||
//设置padding值
|
||||
labelPadding: EdgeInsets.all(8.0),
|
||||
label: Text(dec),
|
||||
//设置onDeleted时候显示的图标
|
||||
deleteIcon: Icon(Icons.delete,color: Colors.white,size: 20.0,),
|
||||
onDeleted: (){
|
||||
deleteIcon: Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
size: 20.0,
|
||||
),
|
||||
onDeleted: () {
|
||||
count++;
|
||||
_modifty();
|
||||
},
|
||||
@ -79,6 +90,3 @@ class _ChipDemoState extends State<ChipDemo> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -9,10 +9,8 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/*
|
||||
* FlatButton 默认按钮的实例
|
||||
* isDisabled:是否是禁用,isDisabled 默认为true
|
||||
* */
|
||||
// FlatButton 默认按钮的实例
|
||||
// isDisabled:是否是禁用,isDisabled 默认为true
|
||||
class FlatButtonDefault extends StatelessWidget {
|
||||
final bool isDisabled;
|
||||
|
||||
@ -29,11 +27,10 @@ class FlatButtonDefault extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* FlatButton.icon 默认按钮的实例
|
||||
* Create a text button from a pair of widgets that serve as the button's icon and label
|
||||
* isDisabled:是否是禁用
|
||||
* */
|
||||
|
||||
// FlatButton.icon 默认按钮的实例
|
||||
// * Create a text button from a pair of widgets that serve as the button's icon and label
|
||||
// * isDisabled:是否是禁用
|
||||
class FlatButtonIconDefault extends StatelessWidget {
|
||||
final bool isDisabled;
|
||||
final IconData icon;
|
||||
@ -63,9 +60,9 @@ class FlatButtonIconDefault extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* FlatButton 自定义的实例
|
||||
* */
|
||||
|
||||
// FlatButton 自定义的实例
|
||||
|
||||
class FlatButtonCustom extends StatelessWidget {
|
||||
final String txt;
|
||||
final Color color;
|
||||
|
@ -47,7 +47,7 @@ class _DemoState extends State<Demo> {
|
||||
Widget build(BuildContext context) {
|
||||
return WidgetDemo(
|
||||
title: 'Checkbox',
|
||||
codeUrl: 'elements/Form/Checkbox/Checkbox/demo.dart',
|
||||
codeUrl: 'elements/Form/CheckBox/Checkbox/demo.dart',
|
||||
contentList: [allCheckboxs(context,this)],
|
||||
docUrl: 'https://docs.flutter.io/flutter/material/Checkbox-class.html',
|
||||
);
|
||||
|
@ -9,10 +9,8 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/*
|
||||
* Checkbox 默认的实例
|
||||
* index 当前checkbox 的索引值
|
||||
* */
|
||||
// Checkbox 默认的实例
|
||||
// index 当前checkbox 的索引值
|
||||
class CheckboxListTileStateDefault extends StatefulWidget {
|
||||
const CheckboxListTileStateDefault() : super();
|
||||
|
||||
@ -20,9 +18,7 @@ class CheckboxListTileStateDefault extends StatefulWidget {
|
||||
State<StatefulWidget> createState() => _CheckboxListTileStateDefault();
|
||||
}
|
||||
|
||||
/*
|
||||
* CheckboxListTile 默认的实例,有状态
|
||||
* */
|
||||
// CheckboxListTile 默认的实例,有状态
|
||||
class _CheckboxListTileStateDefault extends State {
|
||||
bool _value = false;
|
||||
void _valueChanged(bool value) {
|
||||
@ -105,9 +101,7 @@ class _CheckboxListTileStateDefault extends State {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* CheckboxListTile 默认的实例,无状态
|
||||
* */
|
||||
// CheckboxListTile 默认的实例,无状态
|
||||
class CheckboxListTileDefault extends StatelessWidget {
|
||||
final widget;
|
||||
final parant;
|
||||
|
@ -47,7 +47,7 @@ class _DemoState extends State<Demo> {
|
||||
Widget build(BuildContext context) {
|
||||
return WidgetDemo(
|
||||
title: 'CheckboxListTile',
|
||||
codeUrl: 'elements/Form/Checkbox/CheckboxListTile/demo.dart',
|
||||
codeUrl: 'elements/Form/CheckBox/CheckboxListTile/demo.dart',
|
||||
contentList: [allCheckboxs(context, this)],
|
||||
docUrl: 'https://docs.flutter.io/flutter/material/CheckboxListTile-class.html',
|
||||
);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: 一凨
|
||||
* @Date: 2018-11-28 20:44:13
|
||||
* @Last Modified by: 一凨
|
||||
* @Last Modified time: 2018-11-28 20:51:20
|
||||
* @Last Modified time: 2019-01-14 17:02:20
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../../common/widget_demo.dart';
|
||||
@ -37,7 +37,7 @@ class _DemoState extends State<Demo> {
|
||||
],
|
||||
docUrl:
|
||||
'https://docs.flutter.io/flutter/widgets/AnimatedPadding-class.html',
|
||||
codeUrl: 'elements/Frame/spacing/AnimatedPadding/animatedPadding_demo.dart',
|
||||
codeUrl: 'elements/Frame/Spacing/AnimatedPadding/animatedPadding_demo.dart',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: 一凨
|
||||
* @Date: 2018-11-28 20:25:24
|
||||
* @Last Modified by: 一凨
|
||||
* @Last Modified time: 2018-11-28 20:25:24
|
||||
* @Last Modified time: 2019-01-14 17:01:55
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../../common/widget_demo.dart';
|
||||
@ -38,7 +38,7 @@ class _DemoState extends State<Demo> {
|
||||
],
|
||||
docUrl: 'https://docs.flutter.io/flutter/widgets/Padding-class.html',
|
||||
codeUrl:
|
||||
'elements/Frame/spacing/Padding/padding_demo.dart',
|
||||
'elements/Frame/Spacing/Padding/padding_demo.dart',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
/*
|
||||
* @Author: 一凨
|
||||
* @Date: 2018-11-28 20:20:04
|
||||
* @Last Modified by: 一凨
|
||||
* @Last Modified time: 2018-11-28 20:20:49
|
||||
* @Last Modified time: 2019-01-14 16:30:16
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PaddingDemo extends StatelessWidget {
|
||||
@override
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: 一凨
|
||||
* @Date: 2018-11-28 20:26:16
|
||||
* @Last Modified by: 一凨
|
||||
* @Last Modified time: 2018-11-28 20:39:28
|
||||
* @Last Modified time: 2019-01-14 17:06:36
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_go/common/widget_demo.dart';
|
||||
@ -33,7 +33,7 @@ class _DemoState extends State<Demo> {
|
||||
Widget build(BuildContext context) {
|
||||
return WidgetDemo(
|
||||
title: 'SliverPadding',
|
||||
codeUrl: 'elements/Frame/spacing/SliverPadding/sliverpadding_demo.dart',
|
||||
codeUrl: 'elements/Frame/Spacing/SliverPadding/sliverpadding_demo.dart',
|
||||
contentList: [
|
||||
contentDesc0,
|
||||
contentDesc1,
|
||||
|
@ -39,7 +39,7 @@ class _DemoState extends State<Demo> {
|
||||
title: 'IndexedStack',
|
||||
// desc: _desc,
|
||||
codeUrl:
|
||||
'https://github.com/alibaba-paimai-frontend/flutter-common-widgets-app/blob/dev/sanlu-0.0.4/lib/widgets/elements/Frame/Stack/IndexedStack/demo.dart',
|
||||
'elements/Frame/Stack/IndexedStack/demo.dart',
|
||||
docUrl: 'https://docs.flutter.io/flutter/widgets/IndexedStack-class.html',
|
||||
contentList: [
|
||||
_stackText0,
|
||||
|
@ -41,7 +41,7 @@ class _DemoState extends State<Demo> {
|
||||
return WidgetDemo(
|
||||
title: 'Stack',
|
||||
codeUrl:
|
||||
'https://github.com/alibaba-paimai-frontend/flutter-common-widgets-app/blob/dev/sanlu-0.0.4/lib/widgets/elements/Frame/Stack/Stack/demo.dart',
|
||||
'elements/Frame/Stack/Stack/demo.dart',
|
||||
docUrl: 'https://docs.flutter.io/flutter/widgets/Stack-class.html',
|
||||
contentList: [
|
||||
_stackText0,
|
||||
|
@ -168,6 +168,7 @@ flutter:
|
||||
- lib/common/syntax_highlighter.dart
|
||||
|
||||
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
|
Reference in New Issue
Block a user