flutter_nb_utils是一个Flutter开发工具包,提供了各种实用方法、小部件扩展和工具函数,旨在提高开发效率并简化常见任务的实现。
GitHub:https://github.com/bhoominn/nb_utils
pub.dev:https://pub.dev/packages/nb_utils
flutter pub add nb_utils
main.dart
中初始化// 导包
import 'package:nb_utils/nb_utils.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initialize();
runApp(MyApp());
}
return MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: navigatorKey,
home: HomePage(),
);
Text("粗体样式", style: boldTextStyle()),
Text("主题色样式", style: primaryTextStyle()),
Text("辅助文本样式", style: secondaryTextStyle()),
完整代码
import 'package:flutter/material.dart';
import 'package:nb_utils/nb_utils.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Demo Home Page', style: TextStyle(color: Colors.white)),
backgroundColor: Colors.deepPurple,
),
body: Container(
color: Colors.white,
child: Center(
child: Container(
color: Colors.greenAccent,
width: 500,
height: 500,
child: Column(
children: [
Text("粗体样式", style: boldTextStyle()),
Text("主题色样式", style: primaryTextStyle()),
Text("辅助文本样式", style: secondaryTextStyle()),
],
),
),
),
),
),
);
}
}
其提供的功能相当多,可查看文档。
https://github.com/bhoominn/nb_utils