qhd-prevention-flutter/lib/tools/tools.dart

86 lines
2.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'dart:ui';
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
int getRandomWithNum(int min, int max) {
final random = Random();
return random.nextInt(max) + min; // 生成随机数
}
double screenWidth(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return screenWidth;
}
void pushPage(Widget page, BuildContext context) {
Navigator.push(context, MaterialPageRoute(builder: (context) => page));
}
/// 文本样式工具类
/// 文本样式工具类
/// 文本样式工具类,返回 Text Widget
class HhTextStyleUtils {
/// 主要标题,返回 Text
/// [text]: 文本内容
/// [color]: 文本颜色,默认黑色
/// [fontSize]: 字体大小默认16.0
/// [bold]: 是否加粗默认true
static Text mainTitle(
String text, {
Color color = Colors.black,
double fontSize = 16.0,
bool bold = true,
}) {
return Text(
text,
style: TextStyle(
color: color,
fontSize: fontSize,
fontWeight: bold ? FontWeight.bold : FontWeight.normal,
),
);
}
/// 次要标题,返回 Text
/// [text]: 文本内容
/// [color]: 文本颜色,默认深灰
/// [fontSize]: 字体大小默认14.0
/// [bold]: 是否加粗默认false
static Text secondaryTitle(
String text, {
Color color = Colors.black54,
double fontSize = 14.0,
bool bold = false,
}) {
return Text(
text,
style: TextStyle(
color: color,
fontSize: fontSize,
fontWeight: bold ? FontWeight.bold : FontWeight.normal,
),
);
}
/// 小文字,返回 Text
/// [text]: 文本内容
/// [color]: 文本颜色,默认灰色
/// [fontSize]: 字体大小默认12.0
/// [bold]: 是否加粗默认false
static Text smallText(
String text, {
Color color = Colors.black54,
double fontSize = 12.0,
bool bold = false,
}) {
return Text(
text,
style: TextStyle(
color: color,
fontSize: fontSize,
fontWeight: bold ? FontWeight.bold : FontWeight.normal,
),
);
}
}