Flutter图标或象形图插件pictograms的使用

欢迎使用pictograms,这是一个基于OTTAA项目Picto_Widget的新象形图库。

开始使用

此项目用于创建可以在屏幕上动态调整大小的象形图。

如何使用

以下是使用pictograms插件的基本示例:

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:pictograms/pictograms.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // 应用程序的根部件
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pictograms Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const PictoWidgetExample(),
    );
  }
}

class PictoWidgetExample extends StatelessWidget {
  const PictoWidgetExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: GridView.builder(
          padding: const EdgeInsets.all(16),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
            mainAxisExtent: 119,
            childAspectRatio: 1,
            crossAxisSpacing: 12,
            mainAxisSpacing: 4,
          ),
          itemCount: 30,
          itemBuilder: (context, index) {
            return index % 2 == 0
                ? CircularPictogram(
                    onTap: () {
                      print('on tap');
                    },
                    maxFontSize: 15,
                    minFontSize: 0,
                    text: 'UNA BICICLETERIA',
                    image: CachedNetworkImage(
                      imageUrl:
                          "https://static.arasaac.org/pictograms/2282/2282_300.png",
                      fit: BoxFit.cover,
                    ),
                    colorNumber: index % 6 + 1,
                    onLongPress: () {
                      print('long pressed');
                    },
                    disable: index % 3 == 0,
                    customAddColor: index % 4 == 0
                        ? Colors.redAccent
                        : index % 2 == 0
                            ? Colors.green
                            : Colors.white,
                    customProgressColor: Colors.redAccent.shade100,
                    backgroundColor: index % 4 == 0
                        ? Colors.blueGrey
                        : index % 2 == 0
                            ? Colors.white
                            : Colors.blue,
                    textColor: index % 4 == 0
                        ? Colors.white
                        : index % 2 == 0
                            ? Colors.black
                            : Colors.yellowAccent,
                    pictoSize: 180,
                    add: index == 10,
                    iconSize: index == 10 ? 70 : null,
                  )
                : Pictograms(
                    maxFontSize: 11,
                    minFontSize: 0,
                    onTap: () {
                      print('tapped');
                    },
                    text: 'UNA BICICLETERIA',
                    image: CachedNetworkImage(
                      imageUrl:
                          "https://static.arasaac.org/pictograms/2282/2282_300.png",
                      fit: BoxFit.cover,
                    ),
                    colorNumber: index % 6 + 1,
                    onLongPress: () {
                      print('long pressed');
                    },
                    disable: index % 3 != 0,
                    add: index == 21,
                    customAddColor: Colors.redAccent,
                    customProgressColor: Colors.redAccent.shade100,
                    backgroundColor: index % 4 == 0
                        ? Colors.blueGrey
                        : index % 2 == 0
                            ? Colors.white
                            : Colors.blue,
                    textColor: index % 4 == 0
                        ? Colors.white
                        : index % 2 == 0
                            ? Colors.black
                            : Colors.yellowAccent,
                    height: index % 2 == 0 ? 200 : null,
                    width: index % 2 == 0 ? 200 : null,

                    iconSize: index % 4 == 0
                        ? 40
                        : index % 2 == 0
                            ? 80
                            : null,

                  );
          },
        ),
      ),
    );
  }
}

属性

  • text: 设置象形图的名称。
  • onTap: 点击动作。
  • onLongPress: 长按动作。
  • addFunc: 创建另一个函数。
  • height: 自定义小部件的高度。
  • width: 自定义小部件的宽度。
  • add: 创建一个添加按钮。
  • disable: 禁用图标。
  • colorNumber: 小部件的边框颜色。
  • borderRadius: 自定义边框半径。
  • image: 显示的图像或图标。
  • imageUrl: 从网络加载图像。
  • minFontSize: 默认为0的最小字体大小。
  • maxFontSize: 默认为12的最大字体大小。
  • customAddColor: 更改添加图标颜色。
  • customProgressColor: 进度条颜色。
  • backgroundColor: 设置自定义背景颜色,默认为白色。
  • iconSize: 设置添加图标的大小。
  • pictoSize: 仅适用于圆形象形图。
  • roundTitle: 仅在圆形象形图中创建圆标题。
  • roundBorder: 仅在圆形象形图中设置边框大小。

CircularPictogram

如何实现

CircularPictogram(
    onTap: () { print('on tap');},
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    pictoSize:180,
    iconSize: 80
 )

如何实现禁用

CircularPictogram(
    onTap: () { print('on tap');},
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    pictoSize:180,
    iconSize: 80,
    disable: true
 )

如何实现添加功能

CircularPictogram(
    onTap: () { print('on tap');},
    onAdd:(){ print('Add Action')}
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    pictoSize:180,
    iconSize: 80,
    add: true
 )

Pictograms

如何实现

Pictograms(
    onTap: () { print('on tap');},
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    disable: false,
    height:180,
    width:90,
    add:false,
    iconSize: 80
 )

如何实现禁用功能

Pictograms(
    onTap: () { print('on tap');},
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    disable: true,
    height:180,
    width:90,
    add:false,
    iconSize: 80
 )

如何实现添加功能

Pictograms(
    onTap: (){ print('on tap');},
    onAdd: (){print('on Add');}
    maxFontSize: 15,
    minFontSize:0,
    text:'Hello'
    disable: false,
    height:180,
    width:90,
    add:true,
    iconSize: 80
 )
1 回复

更多关于Flutter图标或象形图插件pictograms的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


在Flutter中,你可以使用多种方式来添加图标或象形图(pictograms)。Flutter本身提供了丰富的内置图标,你可以通过Icons类来使用它们。此外,你还可以使用第三方插件来添加自定义图标或象形图。

1. 使用Flutter内置图标

Flutter内置了Material Design图标,你可以通过Icons类来使用它们。例如:

import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Icons Example'),
        ),
        body: Center(
          child: Icon(
            Icons.favorite, // 使用内置的心形图标
            size: 50.0,
            color: Colors.red,
          ),
        ),
      ),
    );
  }
}

void main() => runApp(MyApp());

2. 使用自定义图标字体

如果你需要使用自定义图标,可以将图标字体文件(通常是.ttf文件)添加到你的项目中,并在pubspec.yaml中配置:

flutter:
  fonts:
    - family: MyCustomIcons
      fonts:
        - asset: fonts/MyCustomIcons.ttf

然后,你可以通过IconData类来使用这些自定义图标:

import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Custom Icons Example'),
        ),
        body: Center(
          child: Icon(
            IconData(0xe900, fontFamily: 'MyCustomIcons'), // 使用自定义图标
            size: 50.0,
            color: Colors.blue,
          ),
        ),
      ),
    );
  }
}

void main() => runApp(MyApp());

3. 使用第三方插件

有一些第三方插件可以帮助你更方便地使用图标或象形图。例如,flutter_vector_icons插件提供了多种图标包的集成,包括FontAwesome、Material Icons等。

首先,在pubspec.yaml中添加依赖:

dependencies:
  flutter:
    sdk: flutter
  flutter_vector_icons: ^1.0.0

然后,你可以使用插件提供的图标:

import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Vector Icons Example'),
        ),
        body: Center(
          child: Icon(
            FontAwesome.google, // 使用FontAwesome图标
            size: 50.0,
            color: Colors.green,
          ),
        ),
      ),
    );
  }
}

void main() => runApp(MyApp());

4. 使用象形图插件

如果你需要更复杂的象形图,可以考虑使用flutter_svg插件来加载SVG格式的图标。

首先,在pubspec.yaml中添加依赖:

dependencies:
  flutter:
    sdk: flutter
  flutter_svg: ^0.22.0

然后,你可以使用SvgPicture来加载SVG图标:

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('SVG Icons Example'),
        ),
        body: Center(
          child: SvgPicture.asset(
            'assets/icons/my_icon.svg', // 加载SVG图标
            width: 50.0,
            height: 50.0,
          ),
        ),
      ),
    );
  }
}

void main() => runApp(MyApp());
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!