新手學(xué)習(xí)note漠趁,如有不對(duì)扁凛,還請(qǐng)指出,謝謝??闯传!
TODO
還應(yīng)該加入Text style谨朝、居中 等等
首先,增加空判斷的Text
import 'package:flutter/widgets.dart';
class NonNullText extends Text {
NonNullText(String data) : super(data == Null ? '' : data);
}
- 單純點(diǎn)擊
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'NonNullText.dart';
class ClickableText extends Container {
String text;
VoidCallback onClick;
ClickableText({this.text, this.onClick});
@override
Widget build(BuildContext context) {
String text = this.text;
VoidCallback onClick = this.onClick;
if (onClick == Null) {
onClick = () {};
}
return new Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10.0),
child: GestureDetector(
child: NonNullText(text),
onTap: onClick,
),
);
}
}
使用方法甥绿,傳入text 和 點(diǎn)擊事件字币。
- 點(diǎn)擊跳轉(zhuǎn)到下一頁(yè)面
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutterapp/ui/view/ClickableText.dart';
class RouteText extends ClickableText {
String text;
BuildContext context;
RouteText({this.context, this.text, Widget widget})
: super(
text: text,
onClick: () {
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => widget),
);
});
}
使用方法
new RouteText(
context: context,
text: name,
widget: new WeaponDetail(weapon.id, name));//下一頁(yè)