merge devlop

This commit is contained in:
jianping.xwh
2019-01-08 19:18:12 +08:00
parent 49b86b4c70
commit 94bd8510c0
114 changed files with 6715 additions and 336 deletions

View File

@ -0,0 +1,144 @@
/**
* Created with Android Studio.
* User: 一晟
* Date: 2018/11/22
* Time: 上午12:03
* email: zhu.yan@alibaba-inc.com
* tartget: RaisedButton 的示例
*/
import 'dart:math';
import 'package:flutter/material.dart';
/*
* RaisedButton 默认按钮的实例
* isDisabled:是否是禁用isDisabled 默认为true
* */
enum WhyFarther { harder, smarter, selfStarter, tradingCharter }
class PopupMenuButtonDefault extends StatelessWidget {
final bool isDisabled;
final String type;
const PopupMenuButtonDefault(
[String this.type = 'default1', bool this.isDisabled = true])
: assert(isDisabled != null),
super();
@override
Widget build(BuildContext context) {
switch (type) {
case 'default1':
return default1(context);
break;
case 'default2':
return default2(context);
break;
case 'default3':
return default3(context);
break;
default:
return default1(context);
}
}
Widget default1(BuildContext context) {
return PopupMenuButton<WhyFarther>(
onSelected: (WhyFarther result) {
// setState(() { _selection = result; });
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<WhyFarther>>[
const PopupMenuItem<WhyFarther>(
value: WhyFarther.harder,
child: Text('Working a lot harder'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.smarter,
child: Text('Being a lot smarter'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.selfStarter,
child: Text('Being a self-starter'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.tradingCharter,
child: Text('Placed in charge of trading charter'),
),
],
);
}
Widget default2(BuildContext context) {
return PopupMenuButton(
child: Text('点我试试'),
onSelected: (String value) {},
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem(value: "选项一的内容", child: new Text("选项一")),
new PopupMenuItem(value: "选项二的内容", child: new Text("选项二"))
]);
}
Widget default3(BuildContext context) {
return PopupMenuButton(
//child: Text('点我试试'),// child 和 icon 不能同时用
icon: Icon(Icons.menu),
onSelected: (String value) {},
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem(value: "选项一的内容", child: new Text("选项一")),
new PopupMenuItem(value: "选项二的内容", child: new Text("选项二"))
]);
}
}
class PopupMenuButtonCustom extends StatelessWidget {
final widget;
final parent;
const PopupMenuButtonCustom([this.widget,this.parent])
: super();
@override
Widget build(BuildContext context) {
print('onSelected1:${widget.options}');
final String selectStr = widget.options['defaultSelect'];
return PopupMenuButton(
//如果提供则用于此按钮的widget。
child: RaisedButton.icon(
disabledColor:Colors.red,
icon: Icon(Icons.message, size: 25.0,color:Colors.yellow),
label: Text(
'自定义按钮', style: TextStyle(color: Colors.white),
semanticsLabel: 'FLAT BUTTON'),
// onPressed:(){} // 激活状态按钮
),
// 打开时放置菜单的z坐标。这可以控制菜单下方阴影的大小。
elevation:10.0,
// 如果提供,则用于此按钮的图标。
//icon
// 菜单项的值(如果有),在菜单打开时应突出显示。
//initialValue:options['defaultSelect'],
initialValue:selectStr,
// 按下按钮时调用以创建要在菜单中显示的项目。
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem(value: "选项一的内容", child: new Text("选项一")),
new PopupMenuItem(value: "选项二的内容", child: new Text("选项二")),
new PopupMenuItem(value: "选项三的内容", child: new Text("选项三")),
new PopupMenuItem(value: "选项四的内容", child: new Text("选项四"))
],
// 应用于弹出菜单按钮的偏移量(x,y)。
offset:Offset(0.0,50.0),
// 当用户在不选择项目的情况下关闭弹出菜单时调用。
onCanceled:()=>
print('onCanceled'),
// 当用户从此按钮创建的弹出菜单中选择一个值时调用。
onSelected:(String value){
print('onSelected:${parent.setState}');
parent.setState((){
widget.options['defaultSelect']= value;
});
},
// 默认情况下匹配IconButton的8 dps填充。在某些情况下特别是在此按钮作为列表项的尾随元素出现的情况下能够将填充设置为零是有用的。
padding:new EdgeInsets.only(bottom: 20.0, top: 20.0, left: 0.0, right: 0.0),
//描述按下按钮时将发生的操作的文本。
tooltip:'这是信息'
);
}
}

View File

@ -0,0 +1,90 @@
/**
* Created with Android Studio.
* User: 一晟
* Date: 2018/11/24
* Time: 下午5:25
* email: zhu.yan@alibaba-inc.com
* tartget: PopupMenusButton 的示例
* 对应文档地址:https://docs.flutter.io/flutter/material/PopupMenuButton-class.html
*/
import '../../../../../common/widget-demo.dart';
import '../../../../../routers/application.dart';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import './demo.dart' as popupMenuButton;
const String _titleText0 = """
### **简介**
> 按下时显示菜单
- 当菜单因为选择了项目而被解除时调用onSelected。传递给onSelected的值是所选菜单项的值。
- 可以提供 `child` 或 `icon` 中的一个,但不是能同时设置两者。如果提供了 `icon` ,则 `PopupMenuButton` 的行为类似于 `IconButton`。
- 如果两者都为null则创建一个标准 overflow icon取决于平台
""";
const String _titleText1 = """
### **基本用法**
> 此示例显示一个包含四个项目的菜单
- 在枚举值之间进行选择并_selection根据选择设置字段。
""";
const String _titleText2 = """
### **进阶用法**
> 此示例尝试调整所有属性,展示出效果
- 默认选择第二个。
- 再次打开,`PopupMenuItem` 保留上次的选择结果。
""";
class Demo extends StatefulWidget {
static const String routeName = '/element/Form/Button/PopupMenuButton';
final Map<String,String> options = {'defaultSelect': '选项二的内容'};
@override
final _DemoState self = _DemoState();
_DemoState createState() => self;
}
class _DemoState extends State<Demo> {
String buttonShapeType = 'border'; // 边框类型
void setButtonShapeType(){
String _buttonShapeType = (buttonShapeType == 'border') ? 'radius' : 'border';
this.setState((){
buttonShapeType = _buttonShapeType;
});
}
@override
Widget build(BuildContext context) {
return WidgetDemo(
title: 'PopupMenuButton',
codeUrl: '${Application.github['widgetsURL']}elements/Form/Button/RaisedButton/demo.dart',
child: allPopupMenuButton(widget,this),
docUrl: 'https://docs.flutter.io/flutter/material/PopupMenuButton-class.html',
);
}
}
Widget allPopupMenuButton(Demo widget,State parent){
return Container(
//padding: new EdgeInsets.only(bottom: 20.0, top: 20.0, left: 0, right: 0),
child: Column(
//mainAxisSize: MainAxisSize.max,
children: <Widget>[
MarkdownBody(data: _titleText0),
SizedBox(height: 20.0),
MarkdownBody(data: _titleText1),
Row(
crossAxisAlignment:CrossAxisAlignment.center,
mainAxisAlignment:MainAxisAlignment.spaceBetween,
children: <Widget>[
popupMenuButton.PopupMenuButtonDefault('default1'),
popupMenuButton.PopupMenuButtonDefault('default2'),
popupMenuButton.PopupMenuButtonDefault('default3'),
],
),
SizedBox(height: 20.0),
MarkdownBody(data: _titleText2),
SizedBox(height: 20.0),
popupMenuButton.PopupMenuButtonCustom(widget,parent),
SizedBox(height: 40.0)
]
));
}