当前位置:网站首页>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.
边栏推荐
- Extension of graph theory
- Codeforces Round #804 (Div. 2)
- 力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
- 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
- Ora-01779: the column corresponding to the non key value saving table cannot be modified
- 【LeetCode】18、四数之和
- MySQL if and ifnull use
- ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
- Sliding window problem review
- 驱动开发——HelloWDM驱动
猜你喜欢

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

Principle and performance analysis of lepton lossless compression

Postman前置脚本-全局变量和环境变量

Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected

Yolov5 tensorrt acceleration

Hyperledger Fabric2. Some basic concepts of X (1)

Leetcode dynamic planning day 16
![[classic example] binary tree recursive structure classic topic collection @ binary tree](/img/39/0319c4be43716f927b9d98d89f7655.jpg)
[classic example] binary tree recursive structure classic topic collection @ binary tree

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

Easy to understand I2C protocol
随机推荐
Summary of three log knowledge points of MySQL
[noip2009 popularization group] score line delimitation
Huawei equipment is configured with OSPF and BFD linkage
Class inheritance in yyds dry inventory C
Introduction of several RS485 isolated communication schemes
Programmers' position in the Internet industry | daily anecdotes
Redis has four methods for checking big keys, which are necessary for optimization
yolov5 tensorrt加速
Review of double pointer problems
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
[untitled]
Extension of graph theory
pix2pix:使用条件对抗网络的图像到图像转换
Summary of redis AOF and RDB knowledge points
On the solution of es8316's audio burst
Supreme Court, judgment standard of divorce cases
Biscuits (examination version)
Sliding window problem review
idea一键导包
MPLS experiment