【发布时间】:2019-07-05 13:11:51
【问题描述】:
我需要在具有半透明背景的整个页面上创建自定义加载器。它需要作为共享小部件,因为我需要有可能在不同的页面上启动它。
请帮帮我。
【问题讨论】:
我需要在具有半透明背景的整个页面上创建自定义加载器。它需要作为共享小部件,因为我需要有可能在不同的页面上启动它。
请帮帮我。
【问题讨论】:
我认为您正在尝试构建类似 https://pub.dev/packages/modal_progress_hud 的东西(您可以查看他的 git repo)。
重用 Widget 的方式非常简单。只需在它自己的.dart 文件上创建它。然后只需将其导入您想要使用的位置(以与导入材料相同的方式)。
示例:
import 'package:flutter/material.dart';
import 'components/buttons.dart';
【讨论】:
您可以通过添加 this package 作为依赖项来做到这一点。它是完全可定制的,如果需要,您可以在不同的页面上使用它。
Widget build(BuildContext context) {
return Scaffold(
//// Wrap your body in a stack
body: Stack(
children: <Widget>[
Center(
child: Text("Lorem Ipsum"), //// Your page content
),
//// Put the loader widget at the end of the stack. You can set it to appear based on a boolean. E.g. a loading flag.
EasyLoader(image: AssetImage('assets/loading.png'),)
],
),
);
}
【讨论】: