bmp rogress hud
a lightweight progress hud for your flutter app, inspired by svprogresshud.
example
place progresshud to you container, and get with progresshud.of(context)
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:bmprogresshud/bmprogresshud.dart';
void main() => runapp(myapp());
class myapp extends statelesswidget {
@override
widget build(buildcontext context) {
return materialapp(
home: scaffold(
appbar: appbar(
title: text("hud demo"),
),
body: progresshud(
child: center(
child: builder(builder: (context) {
return column(
mainaxissize: mainaxissize.min,
mainaxisalignment: mainaxisalignment.center,
children: <widget>[
raisedbutton(
onpressed: () {
_showloadinghud(context);
},
child: text("show loading"),
),
],
);
}),
),
),
),
);
}
_showloadinghud(buildcontext context) async {
progresshud.of(context).show(progresshudtype.loading, "loading...");
await future.delayed(const duration(seconds: 1));
progresshud.of(context).dismiss();
}
}
other progresshudtype
// show successhud with text
_showsuccesshud(buildcontext context) {
progresshud.of(context).showanddismiss(progresshudtype.success, "load success");
}
// show errorhud with text
_showerrorhud(buildcontext context) {
progresshud.of(context).showanddismiss(progresshudtype.error, "load fail");
}
// show progresshud with progress and text
_showprogresshud(buildcontext context) {
var hud = progresshud.of(context);
hud.show(progresshudtype.progress, "loading");
double current = 0;
timer.periodic(duration(milliseconds: 1000.0 ~/ 60), (timer) {
current += 1;
var progress = current / 100;
hud.updateprogress(progress, "loading $current%");
if (progress == 1) {
// finished
hud.showanddismiss(progresshudtype.success, "load success");
timer.cancel();
}
});
}
Comments are closed.