Flutter 聊天页面及功能开发

用flutter开发了一个聊天页面  支持发视频,语音,图片,有需要的可以参考一下.

目前功能还不是特别完美,发送语音不太理想,如果哪位有好的方案,也请多多指教

 

import 'dart:async';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:flutter_wanandroid/common/component_index.dart';
import 'package:flutter_wanandroid/data/protocol/messaget_bean_entity.dart';
import 'package:flutter_wanandroid/data/repository/wan_repository.dart';
import 'package:flutter_wanandroid/models/EnmuModels.dart';

import 'package:flutter/scheduler.dart';
import 'package:flutter_wanandroid/models/message_detail_bean_entity.dart';
import 'package:flutter_wanandroid/ui/dialog/simple_dialog.dart';
import 'package:flutter_wanandroid/ui/pages/demos/image_picker_demo.dart';
import 'package:flutter_wanandroid/ui/pages/demos/sound_demo.dart';
import 'package:flutter_wanandroid/ui/pages/demos/video_demo.dart';
import 'package:flutter_wanandroid/ui/widgets/audio_record_button.dart';
import 'package:flutter_wanandroid/ui/widgets/bubble_item.dart';
import 'package:flutter_wanandroid/ui/widgets/message_detail_item.dart';
import 'package:http_parser/http_parser.dart';
import 'package:video_player/video_player.dart';

class MessageDetailPage extends StatefulWidget {
  final MessagetBeanReturnvalueListvo model;

  MessageDetailPage(this.model);

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

class _MessageDetailState extends State<MessageDetailPage> {
  RefreshController _refreshController;
  ScrollController _scrollController;
  List<MessageDetailBeanReturnvalueListvo> data = [];
  int mobileId;

  String mUserId;
  int mDataPage = 0;

  TextEditingController _replyFieldController = new TextEditingController();

  get _result => (result, audioLength) {
        _replyAudioMessage(result, audioLength);
      };

  void _getDatas() {
    mobileId = SpHelper.getIndentityBean().mobileId;
    mUserId = SpHelper.getIndentityBean().userVo.id.toString();
    _onLoading(true);
  }

  void scrollTop() {
    _scrollController.animateTo(0.0,
        duration: const Duration(milliseconds: 200), curve: Curves.linear);
  }

  void enterRefresh() {
    _refreshController.requestRefresh();
  }

  @override
  void dispose() {
    if (flutterSound.isPlaying) flutterSound.stopPlayer();

    super.dispose();
  }

  void _onOffsetCallback(bool isUp, double offset) {}
  FlutterSound flutterSound;

  bool _isPlaying = false;
  StreamSubscription _playerSubscription;

  @override
  void initState() {
    _getDatas();
    _scrollController = ScrollController(keepScrollOffset: true);
    _refreshController = RefreshController();
    flutterSound = new FlutterSound();
    flutterSound.setSubscriptionDuration(0.01);
    flutterSound.setDbPeakLevelUpdate(0.8);
    flutterSound.setDbLevelEnabled(true);

    SchedulerBinding.instance.addPostFrameCallback((_) {
//      _refreshController.requestRefresh(true);
    });
    super.initState();
  }

  bool isRecord = false;
  bool _autovalidate = false;

  void startPlayer(String videoPath) async {
    String path = await flutterSound.startPlayer(videoPath);
    await flutterSound.setVolume(1.0);

    try {
      _playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
        if (e != null) {
          print(
              'startPlayer: ${e.runtimeType}   ${e.currentPosition}   ${e.duration}');
//          slider_current_position = e.currentPosition;
//          max_duration = e.duration;
//
//          DateTime date = new DateTime.fromMillisecondsSinceEpoch(
//              e.currentPosition.toInt(),
//              isUtc: true);
//          String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);
          this.setState(() {
            this._isPlaying = true;
//            this._playerTxt = txt.substring(0, 8);
          });
        }
      });
    } catch (err) {
      print('error: $err');
    }
  }

  @override
  Widget build(BuildContext context) {
    var headView = new Container(
        child: Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Expanded(
            child: Container(
          color: Colors.grey,
          child: SmartRefresher(
              controller: _refreshController,
              enablePullDown: true,
              isNestWrapped: true,
              header: ClassicHeader(
                idleIcon: Container(),
                idleText: "Load more...",
              ),
              enablePullUp: true,
              onRefresh: () {
                _onLoading(true);
              },
              onl oading: () {
                _onLoading(false);
              },
              footer: new ClassicFooter(
                noDataText: '没有更多数据',
                noMoreIcon: Text(""),
              ),
              onOffsetChange: _onOffsetCallback,
              child: ListView.builder(
                itemCount: data.length + 1,
                itemBuilder: _itemBuild,
              )),
        )),
        new Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            new IconButton(
              icon:
                  Image.asset(Utils.getImgPath(isRecord ? 'yuyin' : 'jianpan')),
              onPressed: () {
                setState(() {
                  isRecord = !isRecord;
                });
              },
            ),
            new Expanded(
              child: new Stack(
                children: <Widget>[
                  new Offstage(
                    offstage: isRecord,
                    child: new TextField(
                      controller: _replyFieldController,
                      onSubmitted: (value) {
                        _replyMessage(value);
                      },
                      /*onChanged: (value) {
                  LogUtil.e("onChanged ${value}");

                  LogUtil.e(
                      "onChanged _replyFieldController${_replyFieldController.value.toString()}");
                },*/
                      maxLines: 10,
                      minLines: 1,
                      decoration: new InputDecoration(
                          contentPadding: EdgeInsets.only(
                              left: 8.0, top: 10.0, bottom: 6.0, right: 10.0),
                          labelText: '请输入',
                          fillColor: Colors.blue,
                          border: new OutlineInputBorder(
                              borderSide: BorderSide(color: Colors.blue)),
                          focusedBorder: new OutlineInputBorder(
                              borderSide: BorderSide(color: Colors.blue))),
                      style: TextStyle(color: Colors.black87),
                      focusNode: FocusNode(),
                    ),
                  ),
                  new Offstage(
                    offstage: !isRecord,
                    child: Container(
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: Colors.grey.withAlpha(21),
                          border: Border.all(
                        color: Colors.blueAccent,
                      )),
                      height: 36.0,
                      child:  new AudioRecordButton(_result)),

                  ),
                ],
              ),
            ),
            new IconButton(
              icon: Image.asset(Utils.getImgPath('bj_fabu_tupian')),
              onPressed: () async {
                LocalMediaType result =
                    await Navigator.push(context, new ImagePickerPage());
                print(
                    '${result.mimeType}${result.filePath}${result.width}${result.height}');
                _replyImageMessage(result);
              },
            ),
            new Padding(
                padding: EdgeInsets.only(right: 6.0),
                child: new Theme(
                  data: Theme.of(context).copyWith(
                      buttonTheme: ButtonThemeData(
                          minWidth: 40.0,
                          height: 5,
                          padding: EdgeInsets.only(
                              left: 10.0, top: 0.0, right: 10.0, bottom: 0.0))),
                  child: new RaisedButton(
                    padding: EdgeInsets.only(
                        left: 10.0, top: 2, bottom: 2.0, right: 10.0),
                    onPressed: () {
                      _replyMessage(_replyFieldController.text);
                    },
                    color: Colors.blueAccent,
                    child: Text(
                      "提交",
                      style: TextStyle(color: Colors.white),
                    ),
                    shape: new RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(5.0))),
                  ),
                )),
          ],
        ),
      ],
    ));
    return Scaffold(
      backgroundColor: Theme.of(context).canvasColor,
      appBar: new MyAppBar(
        title: Text("通知详情"),
        centerTitle: true,
      ),
      body: headView,
    );
  }

/*   String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String tempPath = path.replaceAll("-","");
    String contentTypeFor = fileNameMap.getContentTypeFor(tempPath);
    if (contentTypeFor == null) {
      contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
  }*/
  void _replyAudioMessage(String imageResult, int length) {
    Map<String, dynamic> dataMap = {
//      'content': imagePath,
      'userId': mUserId,
      'messageId': widget.model.messageId.toString(),
    };

    if (imageResult != null && length > 0) {
      dataMap.putIfAbsent('musicTime', () {
        return "${length}";
      });

      dataMap.putIfAbsent('music', () {
        return new UploadFileInfo(new File(imageResult),
            imageResult.substring(imageResult.lastIndexOf("/") + 1),
            contentType: ContentType.parse(new MediaType('music',
                    imageResult.substring(imageResult.lastIndexOf(".") + 1))
                .mimeType));
      });
    }

    FormData formData = new FormData.from(dataMap);
    var dialog = showDialog<Null>(
        context: context, //BuildContext对象
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new LoadingDialog(
            //调用对话框
            text: '请等待...',
          );
        });
    wanRepository.replayMessages(formData).then((list) {
      Navigator.pop(context);

      if (mounted)
        setState(() {
          _onLoading(true);
        });
    });
  }

  void _replyImageMessage(LocalMediaType imageResult) {
    Map<String, dynamic> dataMap = {
//      'content': imagePath,
      'userId': mUserId,
      'messageId': widget.model.messageId.toString(),
    };

    if (imageResult.mimeType == 1) {
      String imagePath = imageResult.filePath;
      dataMap.putIfAbsent('photo', () {
        return new UploadFileInfo(new File(imagePath),
            imagePath.substring(imagePath.lastIndexOf("/") + 1),
            contentType:
                ContentType.parse(new MediaType('image', 'jpeg').mimeType));
      });
    } else if (imageResult.mimeType == 2) {
      String imagePath = imageResult.filePath;

      print(
          "${imagePath.substring(imagePath.lastIndexOf("/") + 1)} ${imagePath.substring(imagePath.lastIndexOf(".") + 1)}             ");
      dataMap.putIfAbsent('video', () {
        return new UploadFileInfo(new File(imagePath),
            imagePath.substring(imagePath.lastIndexOf("/") + 1),
            contentType: ContentType.parse(new MediaType('audio',
                    imagePath.substring(imagePath.lastIndexOf(".") + 1))
                .mimeType));
      });
    }

    FormData formData = new FormData.from(dataMap);

    String ownerMobileUserId = widget.model.ownerMobileUserId.toString();
    var dialog = showDialog<Null>(
        context: context, //BuildContext对象
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new LoadingDialog(
            //调用对话框
            text: '请等待...',
          );
        });
    wanRepository.replayMessages(formData).then((list) {
      Navigator.pop(context);
      if (mounted)
        setState(() {
          _onLoading(true);
        });
    });
  }

  void _replyMessage(String content) {
    LogUtil.e(content);
    Map<String, String> dataMap = {
      'content': content,
      'userId': mobileId.toString(),
      'messageId': widget.model.messageId.toString()
    };
    String ownerMobileUserId = widget.model.ownerMobileUserId.toString();
    if (ownerMobileUserId != null) {
      /* dataMap.putIfAbsent("ownerMobileUserId", () {
        return ownerMobileUserId;
      });*/
    }
    var dialog = showDialog<Null>(
        context: context, //BuildContext对象
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new LoadingDialog(
            //调用对话框
            text: '请等待...',
          );
        });
    wanRepository.replayMessages(dataMap).then((list) {
      Navigator.pop(context);
      if (mounted)
        setState(() {
          _replyFieldController.clear();
          _onLoading(true);
        });
    });
  }

  Widget _itemBuild(context, index) => (index == 0)
      ? buildSwiper(context)
      : Item(mobileId.toString(), data[index - 1], flutterSound);

  WanRepository wanRepository = new WanRepository();

  void _onLoading(bool isRefresh) {
    if (isRefresh || mDataPage < 0) {
      mDataPage = 0;
    } else {
      mDataPage++;
    }
    Map<String, String> dataMap = {
      'page': mDataPage.toString(),
      'mobileId': mobileId.toString(),
      'userId': mUserId.toString(),
      'messageId': widget.model.messageId.toString()
    };
    String ownerMobileUserId = widget.model.ownerMobileUserId.toString();
    if (ownerMobileUserId != null) {
      dataMap.putIfAbsent("ownerMobileUserId", () {
        return ownerMobileUserId;
      });
    }
    /* var dialog = showDialog<Null>(
        context: context, //BuildContext对象
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new LoadingDialog(
            //调用对话框
            text: '请等待...',.
          );
        });*/
    wanRepository.getMessageDetail(dataMap).then((list) {
//      Navigator.pop(context);
      if (mounted)
        setState(() {
          if (mDataPage == 0) {
            data.clear();
          }
          if (list == null || list.listVo == null) {
            mDataPage--;
            _refreshController.refreshFailed();
            return;
          }
          if (list.listVo.length <= 0) {
            mDataPage--;
            _refreshController.loadNoData();
            return;
          }
          data.addAll(list.listVo);
          if (!isRefresh) {
            _refreshController.loadComplete();
          } else {
            _refreshController.resetNoData();
            _refreshController.refreshCompleted();
          }
        });
    });
  }

  Widget buildSwiper(BuildContext context) {
    return new Container(
      child: new Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new Text(
              widget.model.msgTitle,
              textAlign: TextAlign.start,
              style: TextStyle(
                  color: Colors.black54,
                  fontSize: 18.0,
                  fontWeight: FontWeight.bold),
            ),
            Gaps.vGap5,
            new Text("时间:${widget.model.createDateApi}"),
            Gaps.vGap10,
            new Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                new Expanded(
                    child: new Text(
                  "发布人:${widget.model.sendName}",
                  maxLines: 1,
                  style: TextStyle(color: Colors.blue),
                )),
                new Expanded(
                    child: new Text("接收人:${widget.model.msgReceiveNames}",
                        style: TextStyle(color: Colors.blue), maxLines: 1)),
                new Text(MessageType.getPushTypeString(widget.model.msgType),
                    style: TextStyle(color: Colors.blue), maxLines: 1),
              ],
            ),
            SizedBox(
                height: 10.0,
                child: Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      border: new Border(
                          bottom: new BorderSide(
                              width: 0.33, color: Colours.divider))),
                )),
            Gaps.vGap5,
            new Container(
                padding: new EdgeInsets.only(right: 13.0),
                child: new Text(
                  widget.model.msgContent,
//                  maxLines: 50,
                ))
          ]),
      padding:
          EdgeInsets.only(left: 18.0, top: 10.0, right: 18.0, bottom: 10.0),
      decoration: new BoxDecoration(
          color: Colors.white,
          border: new Border.all(width: 0.33, color: Colours.divider)),
    );
  }

  PopupMenuButton showChiocePopwin(BuildContext context) {
    return PopupMenuButton(itemBuilder: _popMenuItemBuild);
  }

  List<String> _imageOptions = ['相册', "相机", '选择视频', '录视频'];

  List<PopupMenuEntry> _popMenuItemBuild(BuildContext context) {
    return List.generate(_imageOptions.length, (index) {
      new RaisedButton(
        onPressed: () {},
        child: Text(_imageOptions[index]),
      );
    }).toList();
  }
}

class LocalMediaType {
  final int mimeType;
  final String filePath;
  int width;
  int height;
  int duration;

  LocalMediaType(this.mimeType, this.filePath,
      {this.width, this.height, this.duration});
}

class Item extends StatefulWidget {
  final MessageDetailBeanReturnvalueListvo itemData;
  final String userId;
  final FlutterSound flutterSound;

  Item(this.userId, this.itemData, this.flutterSound);

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

class _ItemState extends State<Item> with TickerProviderStateMixin {
  VideoPlayerController _butterflyController;

  final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
  final Completer<void> connectedCompleter = Completer<void>();
  bool isSupported = true;
  bool isDisposed = false;

  StreamSubscription _playerSubscription;
  var leftSoundNames = [
    'assets/images/sound_left_0.png',
    'assets/images/sound_left_1.png',
    'assets/images/sound_left_2.png' /*,
    'assets/images/sound_left_3.png'*/
  ];
  var rightSoundNames = [
    'assets/images/sound_right_0.png',
    'assets/images/sound_right_1.png',
    'assets/images/sound_right_2.png' /*,
    'assets/images/sound_right_3.png'*/
  ];
  int _animationPosition = 3;
  AnimationController controller;
  Animation animation;

  @override
  void initState() {
    super.initState();
    //控制语音动画
    controller = AnimationController(
        duration: const Duration(milliseconds: 1000), vsync: this);
    final Animation curve =
        CurvedAnimation(parent: controller, curve: Curves.easeOut);
    animation = IntTween(begin: 0, end: 3).animate(curve)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          controller.reverse();
        }
        if (status == AnimationStatus.dismissed) {
          controller.forward();
        }
      });

    if (widget.itemData.videoUrl != null) {
      Future<void> initController(
          VideoPlayerController controller, String name) async {
        controller.setLooping(false);
        controller.setVolume(0.0);
        controller.pause();
        await connectedCompleter.future;
        await controller.initialize();
        if (mounted) {
          setState(() {});
        }
      }

      _butterflyController =
          VideoPlayerController.network(widget.itemData.videoUrl);
      initController(_butterflyController, 'butterfly');
      isIOSSimulator().then<void>((bool result) {
        isSupported = !result;
      });
    }
  }

  void startPlayer(String videoPath) async {
    controller.forward();
    if (widget.flutterSound.isPlaying) {
      widget.flutterSound.stopPlayer();
    }
    String path = await widget.flutterSound.startPlayer(videoPath);
    await widget.flutterSound.setVolume(1.0);

    try {
      _playerSubscription =
          widget.flutterSound.onPlayerStateChanged.listen((e) {
        if (e != null) {
          if (e.duration <= e.currentPosition) {
            controller.reset();
          }
          print(
              'startPlayer: ${e.currentPosition}     ${e.duration}      ${e.runtimeType}');
//          slider_current_position = ;
//          max_duration = ;
//
//          DateTime date = new DateTime.fromMillisecondsSinceEpoch(
//              e.currentPosition.toInt(),
//              isUtc: true);
//          String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);
          if (mounted)
            this.setState(() {
//            this._isPlaying = true;
//            this._playerTxt = txt.substring(0, 8);
            });
        }
      });
    } catch (err) {
      print('error: $err');
    }
  }

  @override
  Widget build(BuildContext context) {
    var itemData = widget.itemData;
//    print("${itemData.musicTime}    ${itemData.musicTime}");
    int _offstate_status = itemData.musicUrl != null && 0 < itemData.musicTime
        ? 3
        : (itemData.photoUrl != null ? 1 : (itemData.videoUrl != null ? 2 : 0));

    if (widget.userId.compareTo(itemData.userId.toString()) != 0) //我发的,在右边

      return Container(
          alignment: Alignment.topRight,
          color: Colors.grey.withAlpha(245),
          padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
          child: Column(
            children: <Widget>[
              Text(
                '${itemData.createDate}',
                style: TextStyle(color: Colors.black54),
              ),
              new Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  new Expanded(
                      child: new Container(
                          padding: EdgeInsets.only(left: 37.0),
                          child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: <Widget>[
                              new Padding(
                                padding: EdgeInsets.only(right: 10.0),
                                child: Text(
                                  '${itemData.userName == null ? "匿名用户" : itemData.userName}',
                                  textAlign: TextAlign.end,
                                  style: TextStyle(
                                      fontSize: 12.0, color: Colors.black54),
                                ),
                              ),
                              Gaps.vGap10,
                              new Stack(
                                children: <Widget>[
                                  new Offstage(
                                    offstage: _offstate_status != 0,
                                    child: new Container(
                                        padding: EdgeInsets.only(
                                            left: 7.0,
                                            top: 9.0,
                                            right: 22.0,
                                            bottom: 5.0),
                                        decoration: BoxDecoration(
                                          image: DecorationImage(
                                            image: AssetImage(
                                                Utils.getImgPath('qipao_you')),
                                            centerSlice: new Rect.fromLTRB(
                                                4.0, 20.0, 5.0, 20.5),
                                          ),
                                        ),
                                        child: Text(
                                          '${itemData.content}',
                                          style: TextStyle(
                                            fontSize: 14.0,
                                          ),
                                          maxLines: 10,
                                        )),
                                  ),
                                  new Offstage(
                                      offstage: _offstate_status != 1,
                                      child: new Container(
                                        padding: EdgeInsets.only(right: 10.0),
                                        child: new ConstrainedBox(
                                          constraints: new BoxConstraints(
                                              maxHeight: 200),
                                          child: new CachedNetworkImage(
                                            fit: BoxFit.fill,
                                            imageUrl: itemData.photoUrl == null
                                                ? "http://126306.sgss8.com/upload/2016042923/232418_1381.jpg"
                                                : itemData.photoUrl,
                                            placeholder: new ProgressView(),
                                            errorWidget: new Icon(Icons.error),
                                          ),
                                        ),
                                      )),
                                  new Offstage(
                                    offstage: _offstate_status != 2,
                                    child: new Container(
                                      padding: EdgeInsets.only(right: 10.0),
                                      child: isSupported &&
                                              _butterflyController != null
                                          ? ConnectivityOverlay(
                                              child: Padding(
                                                padding:
                                                    EdgeInsets.only(left: 10.0),
                                                child: SingleVideoCard(
                                                  controller:
                                                      _butterflyController,
                                                  firstScreen: widget
                                                      .itemData.firstVideoUrl,
                                                ),
                                              ),
                                              connectedCompleter:
                                                  connectedCompleter,
                                              scaffoldKey: scaffoldKey,
                                            )
                                          : const Center(
                                              child: Text(
                                                'Video playback not supported on the iOS Simulator.',
                                              ),
                                            ),
                                    ),
                                  ),
                                  new Offstage(
                                    offstage: _offstate_status != 3,
                                    child: new Container(
                                        width: itemData.musicTime != null &&
                                                60 > itemData.musicTime
                                            ? ((MediaQuery.of(context)
                                                        .size
                                                        .width -
                                                    100) /
                                                60.0 *
                                                (itemData.musicTime < 30
                                                    ? 30
                                                    : itemData.musicTime))
                                            : (MediaQuery.of(context)
                                                    .size
                                                    .width -
                                                100),
                                        padding: EdgeInsets.only(right: 10.0),
                                        child: RaisedButton(
                                          padding: EdgeInsets.only(
                                              left: 8.0, right: 4.0),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Text(
                                                "${itemData.musicTime}\"",
                                                textAlign: TextAlign.start,
                                                maxLines: 1,
                                                style: TextStyle(
                                                    color: Colors.white),
                                              ),
                                              Image.asset(rightSoundNames[
                                                  animation.value % 3])
                                            ],
                                          ),
                                          shape: RoundedRectangleBorder(
                                              borderRadius:
                                                  BorderRadius.circular(18)),
                                          color: Colors.blueAccent,
                                          onPressed: () {
                                            startPlayer(itemData.musicUrl);
                                          },
                                        )),
                                  ),
                                ],
                              )
                            ],
                          ))),
                  Image.network(
                    "http://126306.sgss8.com/upload/2016042923/232418_1381.jpg",
                    width: 35.0,
                    height: 35.0,
                    fit: BoxFit.cover,
                  ),
                ],
              ),
            ],
          ));
    else {
      //对方发的,在左边
      return Container(
          color: Colors.grey.withAlpha(5),
          padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
          child: Column(
            children: <Widget>[
              Text(
                '${itemData.createDate}',
                style: TextStyle(color: Colors.black54),
              ),
              new Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Image.network(
                    "http://126306.sgss8.com/upload/2016042923/232418_1381.jpg",
                    width: 35.0,
                    height: 35.0,
                    fit: BoxFit.cover,
                  ),
                  new Expanded(
                      child: new Container(
                          padding: EdgeInsets.only(right: 38.0),
                          child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              new Padding(
                                padding: EdgeInsets.only(left: 10.0),
                                child: Text(
                                  '${itemData.userName == null ? "匿名用户" : itemData.userName}',
                                  textAlign: TextAlign.start,
                                  style: TextStyle(
                                      fontSize: 12.0, color: Colors.black54),
                                ),
                              ),
                              Gaps.vGap10,
                              new Stack(
                                children: <Widget>[
                                  new Offstage(
                                    offstage: _offstate_status != 0,
                                    child: new Container(
                                        padding: EdgeInsets.only(
                                            left: 27.0,
                                            top: 9.0,
                                            right: 8.0,
                                            bottom: 5.0),
                                        decoration: BoxDecoration(
                                          image: DecorationImage(
                                            fit: BoxFit.fill,
                                            image: AssetImage(
                                                Utils.getImgPath('qipao_zuo')),
                                            centerSlice: new Rect.fromLTRB(
                                                31.0, 24.0, 32.0, 25.0),
                                          ),
                                        ),
                                        child: Text(
                                          '${itemData.content}拉年拉年拉年拉年拉年拉年拉年拉年拉年拉年拉年拉年拉年',
                                          style: TextStyle(
                                            fontSize: 14.0,
                                          ),
                                          maxLines: 10,
                                        )),
                                  ),
                                  new Offstage(
                                    offstage: _offstate_status != 1,
                                    child: new Container(
                                      padding: EdgeInsets.only(left: 10.0),
                                      child: new ConstrainedBox(
                                        constraints:
                                            new BoxConstraints(maxHeight: 200),
                                        child: new CachedNetworkImage(
                                          fit: BoxFit.fill,
                                          imageUrl: itemData.photoUrl == null
                                              ? "http://126306.sgss8.com/upload/2016042923/232418_1381.jpg"
                                              : itemData.photoUrl,
                                          placeholder: new ProgressView(),
                                          errorWidget: new Icon(Icons.error),
                                        ),
                                      ),
                                    ),
                                  ),
                                  new Offstage(
                                    offstage: _offstate_status != 2,
                                    child: isSupported &&
                                            _butterflyController != null
                                        ? ConnectivityOverlay(
                                            child: Padding(
                                              padding:
                                                  EdgeInsets.only(left: 10.0),
                                              child: SingleVideoCard(
                                                controller:
                                                    _butterflyController,
                                                firstScreen: widget
                                                    .itemData.firstVideoUrl,
                                              ),
                                            ),
                                            connectedCompleter:
                                                connectedCompleter,
                                            scaffoldKey: scaffoldKey,
                                          )
                                        : const Center(
                                            child: Text(
                                              'Video playback not supported on the iOS Simulator.',
                                            ),
                                          ),
                                  ),
                                  new Offstage(
                                    offstage: _offstate_status != 3,
                                    child: new Container(
                                        width: itemData.musicTime != null &&
                                                60 > itemData.musicTime
                                            ? ((MediaQuery.of(context)
                                                        .size
                                                        .width -
                                                    100) /
                                                60.0 *
                                                (itemData.musicTime < 30
                                                    ? 30
                                                    : itemData.musicTime))
                                            : (MediaQuery.of(context)
                                                    .size
                                                    .width -
                                                100),
                                        height: 30,
                                        padding: EdgeInsets.only(right: 10.0),
                                        child: RaisedButton(
                                          padding: EdgeInsets.only(
                                              left: 4.0, right: 8.0),
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Image.asset(leftSoundNames[
                                                  animation.value % 3]),
                                              Text(
                                                "${itemData.musicTime}\"",
                                                textAlign: TextAlign.start,
                                                maxLines: 1,
                                                style: TextStyle(
                                                    color: Colors.white),
                                              ),
                                            ],
                                          ),
                                          shape: RoundedRectangleBorder(
                                              borderRadius:
                                                  BorderRadius.circular(15)),
                                          color: Colors.blueAccent,
                                          onPressed: () {
                                            startPlayer(itemData.musicUrl);
                                          },
                                        )),
                                  ),
                                ],
                              )
                            ],
                          ))),
                ],
              ),
            ],
          ));
    }
  }

  @override
  void dispose() {
    print('> VideoDemo dispose');
    isDisposed = true;
    if (_butterflyController != null) _butterflyController.dispose();

    print('< VideoDemo dispose');
    super.dispose();
  }
}

 

原文地址:https://blog.csdn.net/u010883308/article/details/90600296

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“f...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在日常操作中,相信很多人在Flutter怎么使用Android原生播放器问题上存在疑惑,小编查阅了各式资料,整...
Flutter开发的android端如何修改APP名称,logo,版本号,具体的操作步骤:修改APP名称找到文件:android\\app\\src\\main\\AndroidManifest.xml
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.MaterialPageRoute1.3.Navigator1.4.路由传值1.5 命名路由1.6.命名路由参数传递1.7.适配二、路由钩子三、onUnknownRoute四、结尾初识路由概念路由的概念由来已久,包括网络路由、后端路由,到现在广为流行的前端路由。无论路由的概念如何应用,它的核心是一个路由映射表。比如:名字 detail 映射到 DetailPage 页面等。有了这个映射表之后,我们就可以方便的根据名字来完成路由的转发
前提:针对Android开发者(windows系统下),已安装Git,AndroidStudio(建议4.0+版本)一.下载Flutter SDK地址:https://flutter.dev/docs/development/tools/sdk/releases,在 Stable channel (Windows)里面下最新版本即可。Flutter的渠道版本会不停变动,请以Flutter官网为准。在中国,要想正常获取安装包列表或下载安装包,可能需要翻墙,也可以去Flutter github项目下去下载安
一、变量变量是一个引用,根据Dart中“万物皆对象”原则,即变量存储的都是对象的引用,或者说它们都是指向对象。1.1.声明变量://1.不指定类型var name = 'aaa';//2.明确指定类型String name = 'aaa';因为有类型推导,所以两种实现效果一样,官方推荐在函数内的本地变量尽量使用var声明。在变量类型并不明确的情况下,可以使用dynamic关键字//3.使用dynamic关键字dynamic name = 'aaa';1.2.默认值未初始化的变量
前言Flutter2.0发布不久,对web的支持刚刚进入stable阶段。初学几天,构建web应用时候碰到一些问题,比如中文显示成乱码,然后加载图片出现图片跨域问题:Failed to load network image...Trying to load an image from another domain?1.开启web端构建:使用下面这个命令才可以开启Web端构建的支持flutter config --enable-web提示我们:重新启动编辑器,以便它们读取新设置。2.重
一.Flutter打Android release包的步骤:1.为项目创建一个.jks签名文件(很简单,跳过)2.创建一个文件key.properties,直接复制下面key.properties位置如图:在里面输入一下内容:storePassword=iflytekkeyPassword=iflytekkeyAlias=teachingmachinestoreFile=E:/teacher/app/keys/TeachingMachine.jks输入你自己的passwork以及
1 问题Android原生向js发消息,并且可以携带数据2 实现原理Android原生可以使用RCTEventEmitter来注册事件,然后这里需要指定事件的名字,然后在js那端进行监听同样事件的名字监听,就可以收到消息得到数据Android注册关键代码reactContext.getJSModule(DeviceEventManagerModule.RCT...
1 Flexbox布局1) flexDirection 可以决定布局的主轴,子元素是应该沿着水平轴(row)方向排列,还是沿着竖直轴(column)方向排列2) justifyContent 决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式 有flex-start、center、flex-end、space-around...
1 实现的功能在网上看React Native文档,我特码就想实现一个页面到另外一个页面的跳转,然后另外一个页面怎么获取参数,特么没找到一个说清楚的,要么太复杂,要么说了不理解,下面是我自己写的一个App.js文件,实现一个Home页面跳到另外Details页面,并且携带了参数怎么在Details页面获取,就是这么简单粗暴.2 测试DemoApp.js文件如下...
1 问题在一个文件构建一个对象,然后在另外一个文件里面new这个对象,通过构造方法传递参数,然后再获取这个参数2 测试代码Student.js文件如下'use strict';import React from 'react'import {NativeModules, NativeEventEmitter, DeviceEventEmitter,Ale...
1 简单部分代码export default class App extends Component&amp;lt;Props&amp;gt; { render() { return ( &amp;lt;View {styles.container}&amp;gt; &amp;lt;View {styles.welcome}&amp;gt; &amp;l...
1 怎么实现发送和接收事件理论上封装了Android原生广播的代码,需要注册和反注册,这里用DeviceEventEmitter实现//增加监听DeviceEventEmitter.addListener//取消监听//this.emitter.remove();这里可也可以通过安卓原生向页面js发送消息,可以参考我的这篇博客React Native之Android原生通过Dev...
1、Component介绍一般Component需要被其它类进行继承,Component和Android一样,也有生命周期英文图片如下2 具体说明1)、挂载阶段constructor()//构造函数,声明之前先调用super(props)componentWillMount()//因为它发生在render()方法前,因此在该方法内同步设置状态...
1 触摸事件普通点击我们可以使用onPress方法,我们可以使用Touchable 系列控件设计我们的按钮TouchableHighlight 背景会在用户手指按下时变暗TouchableNativeFeedback用户手指按下时形成类似墨水涟漪的视觉效果TouchableOpacity指按下时降低按钮的透明度,而不会改变背景的颜色TouchableWithoutFeedbac...
1 问题部分代码如下class HomeScreen extends React.Component { render() { return ( &amp;lt;View {{ flex: 1, alignItems: 'center', justifyContent: 'center' }}&amp;gt; &amp;lt;Text&amp;gt;Home Scre...
1 Props(属性)和State(状态)和简单样式简单使用App.js代码如下/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow */import React, {Component} from 'react';import {Pla...