123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:smartledz_wifi_test/widgets/animations/animation_for_rotation.dart';
- class Modal {
- // 构建模态框标题
- static Widget buildTitle({
- required String title,
- double? size,
- }){
- return Padding(
- padding: EdgeInsets.only(bottom: 5.sp),
- child: Center(
- child: Text(
- title,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: size ?? 15.sp,
- color: Colors.black,
- )
- ),
- ),
- );
- }
- // 构建文字内容
- static Widget buildContent({
- required String content,
- TextAlign? textAlign,
- }){
- return Text(
- content,
- textAlign: textAlign,
- style: TextStyle(
- fontSize: 15.sp,
- color: const Color(0xAA000000)
- )
- );
- }
- // 构建带边框的输入框
- static Widget buildInputForBorder({
- String? initValue,
- String? hintText,
- List<TextInputFormatter>? inputFormatters,
- TextEditingController? controller,
- void Function(String)? onChanged,
- }){
- return Container(
- height: 40.sp,
- margin: EdgeInsets.symmetric(vertical: 15.sp),
- decoration: BoxDecoration(
- border: Border.all(
- color: const Color(0xAA000000),
- width: .5
- )
- ),
- child: TextFormField(
- controller: controller,
- initialValue: initValue,
- onChanged: onChanged,
- cursorColor: const Color(0xFF00AAFF),
- decoration: InputDecoration(
- hintText: hintText,
- hintStyle: TextStyle(
- fontSize: 15.sp,
- color: Colors.grey.shade500
- ),
- border: const OutlineInputBorder(borderSide: BorderSide.none),
- contentPadding: EdgeInsets.symmetric(horizontal: 10.sp)
- ),
- inputFormatters: inputFormatters,
- style: TextStyle(fontSize: 15.sp),
- ),
- );
- }
- // 构建两个一组的按钮
- static Widget buildButtonForTwo({
- required String leftBtnTitle,
- required String rightBtnTitle,
- void Function()? onLeftBtnTap,
- void Function()? onRightBtnTap,
- }){
- return Row(
- children: [
- GestureDetector(
- onTap: onLeftBtnTap,
- child: Container(
- color: const Color(0xFFAAAAAA),
- padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
- child: Text(leftBtnTitle, style: TextStyle(color: Colors.white, fontSize: 15.sp)),
- ),
- ),
- Expanded(
- child: Align(
- alignment: Alignment.centerRight,
- child: GestureDetector(
- onTap: onRightBtnTap,
- child: Container(
- color: const Color(0xFF00AAFF),
- padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 10.w),
- child: Text(rightBtnTitle, style: TextStyle(color: Colors.white, fontSize: 15.sp)
- ),
- ),
- ),
- ),
- )
- ],
- );
- }
- // 构建自撑宽度的按钮
- static Widget buildButtonForFull({
- required String title,
- void Function()? onTap,
- }){
- return GestureDetector(
- onTap: onTap,
- child: Container(
- alignment: Alignment.center,
- color: const Color(0xFF00AAFF),
- padding: EdgeInsets.symmetric(vertical: 8.h),
- child: Text(title, style: TextStyle(color: Colors.white, fontSize: 15.sp)
- ),
- ),
- );
- }
- // 打开并显示模态框
- static void open({
- required BuildContext context,
- required Widget Function(BuildContext) builder,
- double? width,
- EdgeInsetsGeometry? padding,
- bool disableShadeClose = false, // 禁用遮罩点击关闭
- bool disableReturnKey = false, // 禁用返回键
- }){
- showDialog(
- barrierDismissible: !disableShadeClose,
- context: context,
- builder: (BuildContext context){
- Widget child = UnconstrainedBox(
- child: Container(
- width: width ?? 300.w,
- color: Colors.white,
- padding: padding ?? EdgeInsets.all(15.w),
- child: builder(context),
- ),
- );
- if(disableReturnKey == true){
- return WillPopScope(child: child, onWillPop: () async => false);
- }
- return child;
- }
- );
- }
- // 打开加载遮罩层
- static void openLoading({
- required BuildContext context,
- required String tip,
- }){
- showDialog(
- barrierDismissible: false,
- context: context,
- builder: (BuildContext context){
- return WillPopScope(
- onWillPop: () async => false,
- child: UnconstrainedBox(
- child: Row(
- children: [
- AnimationForRotation(
- duration: const Duration(milliseconds: 400),
- child: Icon(Icons.refresh, color: const Color(0xFF00AAFF), size: 45.sp),
- ),
- SizedBox(width: 10.sp),
- Text(tip, style: TextStyle(color: Colors.white, fontSize: 23.sp, fontWeight: FontWeight.bold))
- ],
- ),
- ),
- );
- }
- );
- }
- // Toast消息提示
- static void toast({
- required String msg
- }){
- Fluttertoast.showToast(
- msg: msg,
- gravity: ToastGravity.TOP,
- backgroundColor: const Color(0xFFEEEEEE),
- textColor: const Color(0xFF00AAFF)
- );
- }
- }
|