Flutter_05_Icon&Color

Icon
  • Flutter 中的图标库
  • Icon(Icons.具体名称)

在线预览

Icon图标

Color(自定义颜色)
  • ​ Flutter中通过ARGB来声明
    • const Color(0xFF42A5F5); //16进制的ARGB=透明度+6位十六位进制颜色
    • const Color.fromARGB(0xFF,0x42,0xA5,0xF5);
    • const Color.fromARGB(255,66,165,254);
    • const Color.fromRGBO(66,165,254,1.0); //O=Opacity
  • Color(英文字母声明的颜色)
    • Colors.red
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  //下一个组件
  runApp(MyApp());
}

//MaterialApp
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Text",
      //下一个组件
      home: Home(),
      //全局设置字体
      // theme: ThemeData(fontFamily: 'SourceSansPro'),
      debugShowCheckedModeBanner: false,
    );
  }
}

//Scaffold
class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Text"),
        leading: Icon(Icons.menu),
        actions: [Icon(Icons.settings)],
        elevation: 0.0,
        centerTitle: true,
      ),
      //下一个组件
      body: TextDemo(),
    );
  }
}

//Container
class TextDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Column的children可以传多个组件
    return Column(
      children: [
        Text(
          //文本内容
          "Flutter可以方便的加入现有的工程中。在全世界,Flutter 正在被越来越多的开发者和组织使用,并且 Flutter是完全免费、开源的。它也是构建未来的 Google Fuchsia 应用的主要方式.Flutter组件采用现代响应式框架构建,这是从React中获得的灵感,中心思想是用组件(widget)构建你的UI。 组件描述了在给定其当前配置和状态时他们显示的样子。当组件状态改变,组件会重构它的描述(description),Flutter 会对比之前的描述, 以确定底层渲染树从当前状态转换到下一个状态所需要的最小更改。",
          //文本方向
          textDirection: TextDirection.ltr,
          // 样式
          style: TextStyle(
            // 字体大小
            fontSize: 30,
            //字体颜色
            color: Colors.red,
            //字体粗细
            fontWeight: FontWeight.w500,
            //字体样式 italic斜体
            fontStyle: FontStyle.italic,
            //文本修饰
            decoration: TextDecoration.lineThrough,
//            修饰颜色
            decorationColor: Colors.blue,
            // 局部设置字体
            fontFamily: 'SourceSansPro',
          ),
          //字体排列
          textAlign: TextAlign.left,
          //最大行数
          maxLines: 3,
          //溢出省略
          overflow: TextOverflow.ellipsis,
          //文本比例
          textScaleFactor: 1.5,
        ),
        //富文本 为文本生成多个样式
        RichText(
          // 文本范围
          text: TextSpan(
            text: "Hello",
            // 文本样式
            style: TextStyle(
              //字体大小
              fontSize: 40,
              // 样式颜色
              color: Color.fromARGB(255, 0, 0, 255),
            ),
            children: [
              TextSpan(
                text: "flutter",
                style: TextStyle(
                  fontSize: 40,
                  color: Colors.blue[200],
                ),
                children: [
                  TextSpan(
                    text: "你好世界",
                    style: TextStyle(
                      fontSize: 40,
                      color: Color.fromARGB(0xFF, 0x00, 0xFF, 0x00
                      ),
                    ),
                    children: [
                      TextSpan(
                        text: 'Dart',
                        style: TextStyle(
                          fontSize: 40,
                          color:Color.fromRGBO(255, 0, 0, 0.5)
                        ),
                      ),
                    ]
                  ),
                ],
              ),
            ],
          ),
        ),
      ],
    );
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现这个功能,你需要先安装腾讯IM的Flutter插件`flutter_im_plugin`和flutter地图插件`flutter_map`。接下来,你需要按照以下步骤进行实现: 1. 引入插件包 在 `pubspec.yaml` 文件中引入以下两个插件: ```yaml dependencies: flutter: sdk: flutter flutter_im_plugin: ^1.1.2 flutter_map: ^0.13.1 ``` 2. 初始化腾讯IM SDK 在使用腾讯IM SDK前,你需要先初始化 SDK。在你的应用程序的启动页面或第一个页面,添加以下代码: ```dart import 'package:flutter_im_plugin/flutter_im_plugin.dart'; void main() async { // 初始化SDK await FlutterImPlugin.init('你的SDKAppID'); runApp(MyApp()); } ``` 3. 发送自定义消息 使用腾讯IM SDK的自定义消息,你可以构建并发送自己的消息。在本例中,我们将发送一个包含位置信息的自定义消息。 ```dart import 'package:flutter_im_plugin/flutter_im_plugin.dart'; void sendLocationMessage(String conversationId, double latitude, double longitude) { // 构建自定义消息 final Map<String, dynamic> customMessage = { 'type': 'location', 'latitude': latitude, 'longitude': longitude, }; // 发送自定义消息 FlutterImPlugin.sendMessage( conversationId, customMessage, messageType: MessageType.Custom, ); } ``` 4. 监听收到的自定义消息 当收到自定义消息时,你需要解析消息并将其显示在地图上。在本例中,我们将使用 `flutter_map` 插件来显示位置信息。 ```dart import 'package:flutter_im_plugin/flutter_im_plugin.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:latlong/latlong.dart'; class MessageDetailPage extends StatefulWidget { final Message message; MessageDetailPage({Key key, this.message}) : super(key: key); @override _MessageDetailPageState createState() => _MessageDetailPageState(); } class _MessageDetailPageState extends State<MessageDetailPage> { MapController _mapController = MapController(); double _latitude; double _longitude; @override void initState() { super.initState(); // 解析自定义消息中的位置信息 final customMessage = widget.message.customMessage; if (customMessage['type'] == 'location') { _latitude = customMessage['latitude']; _longitude = customMessage['longitude']; } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('位置信息'), ), body: FlutterMap( mapController: _mapController, options: MapOptions( center: LatLng(_latitude, _longitude), zoom: 13, ), layers: [ TileLayerOptions( urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', subdomains: ['a', 'b', 'c'], ), MarkerLayerOptions( markers: [ Marker( width: 80.0, height: 80.0, point: LatLng(_latitude, _longitude), builder: (ctx) => Container( child: Icon( Icons.location_on, size: 50.0, color: Colors.red, ), ), ), ], ), ], ), ); } } ``` 在收到自定义消息时,你可以跳转到 `MessageDetailPage` 页面,并将消息对象传递给页面。在页面的 `initState` 方法中解析消息并在地图上显示位置信息。 以上就是使用腾讯IM SDK和 `flutter_map` 插件实现自定义消息发送位置信息并以地图形式展示在聊天框的示例代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值