class Buttondemo extends StatefulWidget {
const Buttondemo({super.key});
@override
State<Buttondemo> createState() => _ButtondemoState();
}
class _ButtondemoState extends State<Buttondemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("按钮组件"),
),
body: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: ElevatedButton(
onPressed: _onPressed, child: const Text("ElevatedButton")),
),
FilledButton(
onPressed: _onPressed, child: const Text("FilledButton")),
FilledButton.tonal(
onPressed: _onPressed, child: const Text("FilledButton.tonal")),
FilledButton.tonalIcon(
onPressed: _onPressed,
label: const Text("FilledButton.tonalIcon")),
OutlinedButton(
onPressed: _onPressed, child: const Text("OutlinedButton")),
TextButton(onPressed: _onPressed, child: const Text("TextButton")),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Ink(
decoration: const ShapeDecoration(
shape: CircleBorder(), color: Colors.blue),
child: IconButton(
onPressed: _onPressed,
iconSize: 30,
icon: const Icon(Icons.import_contacts),
color: Colors.white,
),
),
IconButton(
onPressed: _onPressed,
icon: const Icon(Icons.import_contacts),
iconSize: 30,
style: ButtonStyle(
backgroundColor:
PJButtonBackGroundColor(context, Colors.blue),
foregroundColor:
PJButtonBackGroundColor(context, Colors.white))),
],
),
SizedBox(
width: MediaQuery.of(context).size.width - 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
PJFilledButton(
onPressed: () {
print("置顶");
},
title: "置顶",
bgColors: ColorUtil.hexColorString("#F3AC31"),
fogColors: Colors.white,
),
PJFilledButton(
onPressed: () {
print("优先推广了");
},
title: "优先推广",
bgColors: ColorUtil.hexColorString("#469DBF"),
fogColors: Colors.white),
],
),
)
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _onPressed,
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
label: const Text("FloatingActionButton.extended")),
);
}
void _onPressed() {}
}
class PJFilledButton extends StatelessWidget {
const PJFilledButton(
{super.key,
required this.title,
required this.bgColors,
required this.fogColors,
this.onPressed});
final String title;
final Color bgColors;
final Color fogColors;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return SizedBox(
width: 120,
child: FilledButton(
onPressed: onPressed,
style: ButtonStyle(
backgroundColor: PJButtonBackGroundColor(context, bgColors),
foregroundColor: PJButtonBackGroundColor(context, fogColors)),
child: Text(title),
),
);
}
}
flutter-按钮组件
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...