barrage 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

barrage #

A new Flutter package project.

弹幕展示 #

使用 #

import 'package:barrage/barrage.dart';
BarrageView<TestDataBean>(
                key: _barrageKey,
                data: dataList,
                width: width,
                topPadding: 30,
                itemBgColor: Colors.transparent,
                itemHeight: 24,
                selfItemBgColor: Colors.transparent,
                textColor: Colors.red,
                textSize: 16,
                selfTextColor: Colors.red,
                currentTimeInMs: currentTimeInMs,
                startTimeInSecond: 0,
                clickCallback: () {},
                itemClickCallback: (startX, startY, item) {},
              )

属性说明 #

字段含义
data弹幕数据 Lst
witdh整个弹幕展示宽度
maxLine显示的最大行数
topPadding离顶部距离
itemHeight每个弹幕的高度
itemBgColor每个弹幕的背景颜色
selfItemBgColor自己发的弹幕的背景颜色
textSize每个弹幕的字体大小
textColor每个弹幕的颜色
selfTextColor自己发的弹幕的颜色
startTimeInSecond弹幕起始播放时间
currentTimeInMs当前时间
velocity移动速度
itemClickCallback点击每一个弹幕的回调
verticalPadding弹幕之间的纵向距离
horizontalPadding弹幕之间的横向距离
innerHorizontalPadding每个弹幕本身的水平padding

[0.0.1] 2019-11-21 #

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:barrage/barrage.dart';
import 'dart:convert';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Timer timer;
  int currentTimeInMs = 0;
  List<TestDataBean> dataList = List();
  GlobalKey<BarrageViewState> _barrageKey = new GlobalKey<BarrageViewState>();

  @override
  void initState() {
    super.initState();
    getData();
    timer = Timer.periodic(Duration(milliseconds: 16), (t) {
      currentTimeInMs+=16;
      setState(() {});
    });
  }

  getData() async {
    String data = await rootBundle.loadString("assets/test_data.json");
    var result = json.decode(data);

    if (result is List) {
      result.forEach((item) {
        TestDataBean bean = TestDataBean.fromJson(item);
        dataList.add(bean);
      });

      _barrageKey.currentState.updateBarrageData();
      setState(() {});
    }
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
              child: BarrageView<TestDataBean>(
                key: _barrageKey,
                data: dataList,
                width: width,
                topPadding: 30,
                itemBgColor: Colors.transparent,
                itemHeight: 24,
                selfItemBgColor: Colors.transparent,
                textColor: Colors.red,
                textSize: 16,
                selfTextColor: Colors.red,
                currentTimeInMs: currentTimeInMs,
                startTimeInSecond: 0,
                clickCallback: () {},
                itemClickCallback: (startX, startY, item) {},
              ),
            ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          timer.cancel();
        },
        tooltip: 'stop',
        child: Icon(Icons.pause),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class TestDataBean extends BarrageItemBean {
  int commentId;
  String content;
  String createTime;
  int danmuTime;
  bool isFake;

  factory TestDataBean.fromJson(Map<String, dynamic> json) => TestDataBean(
      commentId: json['commentId'] as int,
      content: json['content'] as String,
      createTime: json['createTime'] as String,
      danmuTime: json['danmuTime'] as int,
      isFake: json['isFake'] as bool);

  TestDataBean(
      {this.commentId,
      this.content,
      this.createTime,
      this.danmuTime,
      this.isFake});

  @override
  getBarrageContent() {
    return content;
  }

  @override
  getBarrageCreateTime() {
    return createTime;
  }

  @override
  getBarrageId() {
    return commentId;
  }

  @override
  getBarrageShowTime() {
    return danmuTime;
  }

  @override
  isSelf() {
    return isFake;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  barrage: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:barrage/barrage.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Apr 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test