86 lines
2.2 KiB
Dart
86 lines
2.2 KiB
Dart
|
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,
|
|||
|
),
|
|||
|
);
|
|||
|
}
|
|||
|
}
|