当前位置:网站首页>Fluent implements a loadingbutton with loading animation
Fluent implements a loadingbutton with loading animation
2022-07-06 05:10:00 【Bright as water】
Preface
Today I share a button that loads animation again , I hope I can help you , Just replace the loading icon . The renderings are as follows :

One 、loading Component code
import "dart:math" as math;
import 'package:flutter/material.dart';
class HBLoadingButton extends StatefulWidget {
bool loading;
String title;
Function callback;
bool isActive; // Is it active
// Button height
double? height = 40.0;
HBLoadingButton(this.loading, this.title, this.callback, {this.height, this.isActive = true});
@override
_HBLoadingButtonState createState() => _HBLoadingButtonState();
}
class _HBLoadingButtonState extends State<HBLoadingButton> with SingleTickerProviderStateMixin {
AnimationController? _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 100 * 15),
)..repeat();
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
Widget _btn() {
return Container(
decoration: widget.isActive
? BoxDecoration(
color: Color(0xFF006CFF),
borderRadius: BorderRadius.circular(8.0),
)
: BoxDecoration(
color: Color(0x1F0C0C1C),
borderRadius: BorderRadius.circular(8.0),
),
height: widget.height,
child: TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Color(0xFF006CFF)),
),
child: Text(
widget.title,
style: widget.isActive
? const TextStyle(fontSize: 16.0, color: Color(0xFFFFFFFF))
: const TextStyle(fontSize: 16.0, color: Color(0x800C0C1C)),
),
onPressed: () {
widget.callback();
},
),
);
}
Widget _loadingBtn() {
Widget icon = Image.asset(
"lib/common/assets/ic_loading_more_white.png",
width: 16,
height: 16,
);
if (_controller != null) {
icon = AnimatedBuilder(
animation: _controller!,
builder: (_, Widget? child) {
return Transform.rotate(
angle: _controller!.value * 2 * math.pi,
child: child,
);
},
child: icon,
);
}
return Container(
decoration: BoxDecoration(
color: Color(0xFF006CFF),
borderRadius: BorderRadius.circular(8.0),
),
height: widget.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
" Loading ...",
style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 14.0),
),
Container(
margin: const EdgeInsets.only(left: 6.0),
child: icon,
),
],
),
);
}
@override
Widget build(BuildContext context) {
return widget.loading ? _loadingBtn() : _btn();
}
}
Two 、 Use the code
import 'package:flutter/material.dart';
import 'package:flutter_hotsmeta/module/beginner_guide/page/hb_loading_button.dart';
class HBLoadingPage extends StatefulWidget {
const HBLoadingPage({Key? key}) : super(key: key);
@override
State<HBLoadingPage> createState() => _HBLoadingPageState();
}
class _HBLoadingPageState extends State<HBLoadingPage> {
bool requesting = false;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text(" Test load button "),
),
body: _buildMainWidget(context),
);
}
_buildMainWidget(BuildContext context) {
return Center(
child: SizedBox(
width: 291.0,
height: 40.0,
child: HBLoadingButton(
requesting,
" determine ",
_beforeConfirm,
),
),
);
}
_beforeConfirm() {
setState(() {
requesting = true;
});
Future.delayed(const Duration(milliseconds: 5000), () {
setState(() {
requesting = false;
});
});
}
}
END.
边栏推荐
- Mongodb basic knowledge summary
- 关于imx8mp的es8316的芯片调试
- ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
- Leetcode dynamic planning day 16
- Chip debugging of es8316 of imx8mp
- What should the project manager do if there is something wrong with team collaboration?
- 组播和广播的知识点梳理
- 浅谈镜头滤镜的类型及作用
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Implementing fuzzy query with dataframe
猜你喜欢

【OSPF 和 ISIS 在多路访问网络中对掩码的要求】

Imperial cms7.5 imitation "D9 download station" software application download website source code

Summary of redis basic knowledge points

从0到1建设智能灰度数据体系:以vivo游戏中心为例

Extension of graph theory

图论的扩展

Huawei equipment is configured with OSPF and BFD linkage

ORM aggregate query and native database operation
![[mathematical modeling] differential equation -- sustainable development of fishing industry](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
[mathematical modeling] differential equation -- sustainable development of fishing industry

ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
随机推荐
SQL injection vulnerability (MSSQL injection)
Some common skills on unity inspector are generally used for editor extension or others
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Basic knowledge and examples of binary tree
力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
Talking about the type and function of lens filter
Imperial cms7.5 imitation "D9 download station" software application download website source code
Ora-01779: the column corresponding to the non key value saving table cannot be modified
图论的扩展
Upload nestjs configuration files, configure the use of middleware and pipelines
Three methods of Oracle two table Association update
Three. JS learning - light and shadow (understanding)
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
你需要知道的 TCP 三次握手
EditorUtility.SetDirty在Untiy中的作用以及应用
趋势前沿 | 达摩院语音 AI 最新技术大全
Postman断言
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
集合详解之 Collection + 面试题
Programmers' position in the Internet industry | daily anecdotes