Flutter可能提供的特定功能插件moye的介绍与使用

Flutter可能提供的特定功能插件moye的介绍与使用

Moye介绍

一个旨在减少创建精美用户界面所需代码量的Flutter软件包。

Extensions

厌倦了在每个小部件周围包裹Expanded小部件来使其扩展吗?您可以使用expanded小部件来避免在多个层的小部件周围包裹您的小部件并使代码更易读。

// Before
Expanded(child: YourCustomWidget())

// After
YourCustomWidget().expanded

Extensions不止于此。您还可以在扩展上递归调用扩展以实现所需的UI,并使代码更易读。例如:

// Before
Column(
  children: [
    Expanded(
      child: Padding(
        padding: EdgeInsets.all(16),
        child: Container(
          child: Align(
            alignment: Alignment.topCenter,
            child: Text('Test'),
          ),
        ),
      ),
    ),
    Expanded(
      child: Padding(
        padding: EdgeInsets.all(8),
        child: Container(
          child: Align(
            alignment: Alignment.centerRight,
            child: Text('Test'),
          ),
        ),
      ),
    )
  ],
);

// After using extensions
Column(
  children: [
    Container(
      child: Text('Test').alignTop,
    ).withPadding(s16Padding).expanded,
    Container(
      child: Text('Test').alignRight,
    ).withPadding(s8Padding).expanded,
  ],
);

如您从上述代码中看到的那样,您可以使用Moye中的预定义常量来处理填充、尺寸和间距。Moye目前有许多扩展以满足您的需求,但是,如果您的用例尚未被覆盖,请打开一个新的请求。

常量

Moye中的预定义常量使您可以轻松地将它们集成到项目中并保持整洁。

填充常量

高频使用的填充模式在此包中得到了涵盖。您可以看到以下差异:

// Before

1. const EdgeInsets.all(8)
2. const EdgeInsets.symmetric(vertical: s8)
3. const EdgeInsets.symmetric(horizontal: s8)

// After

1. s8Padding
2. s8VerticalPadding
3. s8HorizontalPadding
盒子常量

盒子允许您定义不同小部件之间的空间。

// Before

1. SizedBox()
2. SizedBox(width: 8)
3. SizedBox(height: 8)

// After

1. empty
2. s8WidthBox
3. s8HeightBox

Gradient Overlay

在您的小部件顶部添加渐变覆盖,使其更加独特。您可以将这些着色器应用于Text、Image以及其他您当前拥有的小部件。渐变覆盖也有一个可以轻松调用的扩展!

Column(
  crossAxisAlignment: CrossAxisAlignment.stretch,
  children: [
    Text('Gradient Overlay', style: context.textTheme.headlineLarge.bold),
    s8HeightBox,
    Text('Here is how gradient overlay looks' * 5)
  ],
).withGradientOverlay(
  gradient: LinearGradient(
    colors: [
      context.colorScheme.primary,
      context.colorScheme.tertiary,
      context.colorScheme.primary,
    ],
  ),
)

Glow Container

为您的任何小部件添加背光效果。这将增强您的UI/UX并使其更具未来感!您可以自定义颜色、模糊半径和散布半径,并且它自带扩展!

YourWidget().withGlowContainer(blurRadius: 10)

Linear Gradient Progress Bar

让您的线性进度条支持渐变颜色和背景阴影!

LinearGradientProgressBar(
  value: 0.3,
  borderRadius: BorderRadius.circular(56),
  gradient: LinearGradient(
    colors: [
      context.colorScheme.primary,
      context.colorScheme.tertiary,
    ],
  ),
)

Progress Button

在执行操作时向用户提供反馈,并在任务完成之前阻止任何传入的按钮点击。

ProgressButton(
  onPressed: () async {
    await Future.delayed(const Duration(seconds: 1));
  },
  child: const Text('Progress button - inside loading'),
  icon: Icon(Icons.send),
)

BottomSheet Utils

轻松显示三种不同类型的底部弹出菜单:默认、包裹和可滚动。

BottomSheetUtils.showBottomSheet(
  context: context,
  borderRadius: BorderRadius.circular(16),
  config: WrapBottomSheetConfig(
    builder: (context, controller) {
      return buildBottomSheetContent(context, 'Wrap',
          'This type of bottom sheet wraps its content');
    },
  ),
);

Back Blur Image

对任何图像进行模糊处理,并将其放置在任何小部件后面以增强您的UI/UX。

Container(
  width: 100,
  height: 100,
).withBackBlurImage(
    imageProvider: NetworkImage(
        'https://i.natgeofe.com/n/b103fff5-6a84-4d19-b65e-5856998816c3/PIA19952.jpg?w=1440&h=1440')),
)

示例代码

import 'package:example/showcase_widget.dart';
import 'package:flutter/material.dart';
import 'package:moye/moye.dart';
import 'package:moye/widgets/gradient_overlay.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      themeMode: ThemeMode.dark,
      darkTheme: ThemeData(
          brightness: Brightness.dark,
          useMaterial3: true,
          colorSchemeSeed: Colors.blue.shade900),
      theme: ThemeData(
          brightness: Brightness.light,
          useMaterial3: true,
          colorSchemeSeed: Colors.blue.shade900),
      home: MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  [@override](/user/override)
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: FadeContainer.bottom(
          context: context,
          child: ListView(
            padding: s16Padding,
            children: [
              ShowcaseWidget(
                child: Column(
                  children: [
                    Text('Here are the capabilities of this package',
                        style: context.textTheme.titleMedium)
                  ],
                ),
              ),
              ShowcaseWidget(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    Text('Gradient Overlay',
                        style: context.textTheme.headlineLarge.bold),
                    s8HeightBox,
                    Text('Here is how gradient overlay looks' * 5)
                  ],
                ).withGradientOverlay(
                  gradient: LinearGradient(
                    colors: [
                      context.colorScheme.primary,
                      context.colorScheme.tertiary,
                      context.colorScheme.primary,
                    ],
                  ),
                ),
              ),
              ShowcaseWidget(
                title: 'Glow Container',
                description:
                    'Adds an outer glow to the given widget. This is a similar glow that changing the elevation of a widget provides you, however, you can customize the outer glow by [color], [blurRadius], and [spreadRadius]',
                child: empty,
              ).withGlowContainer(blurRadius: 10),
              ShowcaseWidget(
                title: 'Linear Gradient Progress Bar',
                description:
                    'a progress bar that can have gradient colors and box shadows with animation when value changes',
                child: LinearGradientProgressBar(
                  value: 0.3,
                  borderRadius: BorderRadius.circular(56),
                  gradient: LinearGradient(colors: [
                    context.colorScheme.primary,
                    context.colorScheme.tertiary,
                  ]),
                ),
              ),
              ShowcaseWidget(
                title: 'Progress Button',
                description:
                    'A button that shows circular progress bar or a custom widget when pressed until the future task is complete. Useful to make show a feedback to the user when they press a button and debounce any incoming press events while the task is in progress.',
                child: Column(
                  children: [
                    ProgressButton(
                      onPressed: () async {
                        await Future.delayed(const Duration(seconds: 1));
                      },
                      child: const Text('Progress button - inside loading'),
                      icon: Icon(Icons.send),
                    ),
                    s16HeightBox,
                    ProgressButton(
                      loadingType: ProgressButtonLoadingType.replace,
                      onPressed: () async {
                        await Future.delayed(const Duration(seconds: 1));
                      },
                      child: const Text('Progress button - replace loading'),
                      icon: Icon(Icons.send),
                    ),
                  ],
                ),
              ),
              ShowcaseWidget(
                title: 'Bottom Sheet Utils',
                description: 'Show default, wrap, and scrollable bottom sheets',
                child: Row(
                  children: [
                    ElevatedButton(
                      onPressed: () {
                        BottomSheetUtils.showBottomSheet(
                          context: context,
                          borderRadius: BorderRadius.circular(16),
                          config: DefaultBottomSheetConfig(
                            builder: (context, controller) {
                              return buildBottomSheetContent(context, 'Default',
                                  'This bottom sheet has 50 percent of screen as its height with no modification');
                            },
                          ),
                        );
                      },
                      child: Text('Default'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        BottomSheetUtils.showBottomSheet(
                          context: context,
                          borderRadius: BorderRadius.circular(16),
                          config: WrapBottomSheetConfig(
                            builder: (context, controller) {
                              return buildBottomSheetContent(context, 'Wrap',
                                  'This type of bottom sheet wraps its content');
                            },
                          ),
                        );
                      },
                      child: Text('Wrap'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        BottomSheetUtils.showBottomSheet(
                          context: context,
                          borderRadius: BorderRadius.circular(16),
                          config: ScrollableBottomSheetConfig(
                            builder: (context, controller) {
                              return SingleChildScrollView(
                                controller: controller,
                                child: buildBottomSheetContent(
                                    context,
                                    'Scrollable',
                                    'This type of bottom sheet allows it to be draggable'),
                              );
                            },
                          ),
                        );
                      },
                      child: Text('Scrollable'),
                    ),
                  ],
                ),
              ),
              ShowcaseWidget(
                title: 'Back Blur Image',
                description:
                    'Shows the child on top of the blurred version of the image provider provided. Useful to make the background of a widget blurry.',
                child: Container(
                  width: 100,
                  height: 100,
                ).withBackBlurImage(
                    imageProvider: NetworkImage(
                        'https://i.natgeofe.com/n/b103fff5-6a84-4d19-b65e-5856998816c3/PIA19952.jpg?w=1440&h=1440')),
              ),
            ],
          ),
        ),
      ),
    );
  }

  SafeArea buildBottomSheetContent(
      BuildContext context, String bottomSheetType, String description) {
    return SafeArea(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          const BottomSheetHandle().alignCenter,
          s8HeightBox,
          Text('$bottomSheetType Bottom Sheet',
                  style: context.textTheme.headlineMedium.bold)
              .withPadding(s16HorizontalPadding),
          s4HeightBox,
          Text(description).withPadding(s16HorizontalPadding),
          s32HeightBox,
        ],
      ),
    );
  }
}

更多关于Flutter可能提供的特定功能插件moye的介绍与使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter可能提供的特定功能插件moye的介绍与使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


Flutter 插件 moye 的介绍与使用指南

虽然目前关于 Flutter 插件 moye 的官方介绍为“undefined”,但基于其名称和常见插件功能,我们可以合理推测其可能的用途和功能。以下是对 moye 插件的介绍与使用指南,供开发者参考。

1. 插件名称推测

“Moye”可能代表某种特定功能或工具的简称。根据常见的 Flutter 插件命名习惯,moye 可能涉及以下领域:

  • 多媒体处理:如音频、视频的播放或编辑。
  • 网络通信:如特定的 API 请求封装或 WebSocket 实现。
  • UI 组件:如自定义动画、界面元素或布局工具。
  • 数据存储:如本地数据库或缓存管理。
  • 硬件交互:如相机、传感器或蓝牙功能。

以下内容将基于“多媒体处理”功能进行假设性介绍。


2. 插件功能假设

假设 moye 是一个用于处理多媒体内容的 Flutter 插件,其主要功能可能包括:

  • 音频/视频播放:支持多种格式的媒体文件播放。
  • 媒体编辑:提供简单的剪切、合并或滤镜功能。
  • 流媒体支持:支持网络流媒体的加载与播放。
  • 自定义控件:提供可定制的播放器 UI 组件。

3. 安装插件

pubspec.yaml 文件中添加 moye 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  moye: ^1.0.0 # 假设版本号为1.0.0

运行 flutter pub get 安装插件。


4. 基本用法

以下是一个假设性的使用示例,展示如何使用 moye 插件进行视频播放:

import 'package:flutter/material.dart';
import 'package:moye/moye.dart'; // 导入moye插件

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: VideoPlayerScreen(),
    );
  }
}

class VideoPlayerScreen extends StatefulWidget {
  [@override](/user/override)
  _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  late MoyeVideoPlayerController _controller;

  [@override](/user/override)
  void initState() {
    super.initState();
    // 初始化播放器控制器
    _controller = MoyeVideoPlayerController.network(
      'https://example.com/sample-video.mp4', // 视频URL
    )..initialize().then((_) {
        setState(() {});
      });
  }

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Video Player')),
      body: Center(
        child: _controller.value.isInitialized
            ? AspectRatio(
                aspectRatio: _controller.value.aspectRatio,
                child: MoyeVideoPlayer(_controller),
              )
            : CircularProgressIndicator(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _controller.value.isPlaying
                ? _controller.pause()
                : _controller.play();
          });
        },
        child: Icon(
          _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
        ),
      ),
    );
  }

  [@override](/user/override)
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
回到顶部