Flutter 库:强大的工具及扩展——nb_utils

Flutter 库:强大的工具及扩展——nb_utils

文章目录

  • Flutter 库:强大的工具及扩展——nb_utils
  • 一、概述
    • 1、简介
    • 2、功能
    • 3、官方资料
  • 二、基本使用
    • 1、安装
    • 2、基本使用
      • 第一步:在 `main.dart` 中初始化
      • 第二步:在您的 MaterialApp 或 CupertinoApp 中添加导航键
      • 第三步:使用文本样式
    • 3、运行结果
  • 三、其它

一、概述

1、简介

flutter_nb_utils是一个Flutter开发工具包,提供了各种实用方法、小部件扩展和工具函数,旨在提高开发效率并简化常见任务的实现。

2、功能

  • Useful Methods: 介绍了一些有用的方法。
  • Use of TextStyle: 文本样式的使用。
  • Shared Preference Example: 共享首选项的示例。
  • MaterialYou Theme: 材料你主题的介绍。
  • Decorations: 装饰品的使用方法。
  • Widgets: Flutter中常用的小部件介绍。
  • Extensions: 扩展方法的使用和介绍。
    • String Extensions: 字符串的扩展方法。
    • bool Extensions: 布尔类型的扩展方法。
    • Color Extensions: 颜色的扩展方法。
    • BuildContext Extensions: 构建上下文的扩展方法。
    • DateTime Extensions: 日期时间的扩展方法。
    • Device Extensions: 设备的扩展方法。
    • double Extensions: 双精度数值的扩展方法。
    • Duration Extensions: 持续时间的扩展方法。
    • int Extensions: 整数的扩展方法。
    • List Extensions: 列表的扩展方法。
    • num Extensions: 数值的扩展方法。
    • ScrollController Extensions: 滚动控制器的扩展方法。
    • Widget Extensions: 小部件的扩展方法。
  • System Methods: 系统方法的介绍。
  • Network Utils: 网络实用程序的使用方法。
  • JWT Decoder: 智威汤逊解码器的介绍。
  • Dialog: 对话框的使用方法。
  • Custom Dialogs: 自定义对话框的介绍。

3、官方资料

GitHub:https://github.com/bhoominn/nb_utils

pub.dev:https://pub.dev/packages/nb_utils

二、基本使用

1、安装

flutter pub add nb_utils

2、基本使用

第一步:在 main.dart 中初始化

// 导包
import 'package:nb_utils/nb_utils.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await initialize();

  runApp(MyApp());
}

第二步:在您的 MaterialApp 或 CupertinoApp 中添加导航键

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()),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

3、运行结果

Flutter 库:强大的工具及扩展——nb_utils_第1张图片

三、其它

其提供的功能相当多,可查看文档。

https://github.com/bhoominn/nb_utils

你可能感兴趣的:(Flutter,flutter,android)