invitation_addition_page.dart 30.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
import 'package:flutter/material.dart';

import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';

import 'package:one_key/widgets/system_app_bar.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';

import '../../models/upload_img_model.dart';
import '../../provider/upload_img_provider.dart';
import '../../res/colors.dart';
import '../../utils/screen_util.dart';
import '../../utils/upload_image_util.dart';
import '../../utils/utils.dart';
import 'dart:io';

/**
 * 预订信息模块设置-自定义图文默认
 */

class AdditionModel {
  String content;
  String type; // 1图片 2文本
  int order; //顺序
  UploadImgModel image;
  TextEditingController infoC = TextEditingController();

  AdditionModel();

  factory AdditionModel.fromJson(Map<String, dynamic> json) => AdditionModel()
    ..content = json["content"]
    ..type = json["type"]
    ..order = json['order'];

  Map<String, dynamic> toJson() =>
      <String, dynamic>{"content": content, "type": type, 'order': order};
}

class InvicationAdditionPage extends StatefulWidget {
  InvicationAdditionPage();

  @override
  State<InvicationAdditionPage> createState() => _InvicationAdditionPageState();
}

class _InvicationAdditionPageState extends State<InvicationAdditionPage> {
  TextEditingController titleC = TextEditingController();
  List<AdditionModel> data = [];
  UploadImageProvider _uploadImageProvider;
  final picker = ImagePicker();
  ScrollController controller = ScrollController();

  @override
  void initState() {
    super.initState();

    AdditionModel additionModel = AdditionModel();
    additionModel.content =
        'https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641';
    additionModel.type = '1';
    additionModel.order = 0;
    additionModel.image = UploadImgModel();
    additionModel.image.process = 1;
    additionModel.image.qiniuUrl =
        'https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641';

    AdditionModel additionModel1 = AdditionModel();
    additionModel1.content = 'webenkjfkdfjakdfjaldfkjaldfjaldf';
    additionModel1.type = '2';
    additionModel1.order = 1;

    data.add(additionModel);
    data.add(additionModel1);

    WidgetsBinding.instance.addPostFrameCallback((_) async {
      _getQiniuInfo();
    });
  }

  ///获取七牛云token
  ///
  _getQiniuInfo() async {
    await _uploadImageProvider.getQiniuInfo(context, {});
  }

  @override
  void dispose() {
    super.dispose();
    _uploadImageProvider.tableImageList = [];
  }

  ///#相机拍照,单图选择
  Future _getFromPictureOrCamera(UploadImgModel imgModel, imageSource) async {
    final pickedFile = await picker.pickImage(source: imageSource);
    File compressedFile = await FlutterNativeImage.compressImage(
        pickedFile.path,
        quality: 50,
        percentage: 50);
    setState(() {
      if (pickedFile != null) {
        imgModel.file = File(pickedFile.path);
        imgModel.process = 0.01;
      } else {
        print('No image selected.');
      }
    });
    if (pickedFile != null) {
      // if (title == '头像') {
      //   _uploadImageProvider.imgSizeTouxiang = 76;
      //   _uploadImageProvider.touxiang.qiniuUrl = null;
      // } else {
      // _uploadImageProvider.imgSizeErweima = 76;
      _uploadImageProvider.firstImage.qiniuUrl = null;
      // }
      bool need = await Utils.sizeNeed(File(pickedFile.path));
      File file = File(pickedFile.path);
      if (need) {
        file = File(compressedFile.absolute.path);
      }
      UploadImageUtil()
          .startUploadOnly(context, file, 4, true, _uploadImageProvider);
    }
  }

  ///添加图片UI弹出
  Future _openModalBottomSheet(context) async {
    final option = await showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        isDismissible: false,
        builder: (BuildContext context) {
          return Container(
            // height: ScreenUtil().setWidth(180 * 2),
            decoration: BoxDecoration(
                color: MyColours.color_ffffff,
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(ScreenUtil().setWidth(24)),
                    topRight: Radius.circular(ScreenUtil().setWidth(24)))),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                InkWell(
                  onTap: () {
                    // Utils.getPickPermission(context, () {
                    //   _getFromPictureOrCamera(
                    //       _uploadImageProvider.firstImage, ImageSource.camera);

                    //   Navigator.pop(context);
                    // }, Permission.camera);
                    Utils.getPickPermission(context, () {
                      _getFromPictureOrCamera(
                          _uploadImageProvider.firstImage, ImageSource.camera);
                      Navigator.pop(context);
                    },
                        Platform.isAndroid
                            ? Permission.storage
                            : Permission.photos);
                  },
                  child: Container(
                      width: double.infinity,
                      height: ScreenUtil().setWidth(58 * 2),
                      child: Center(
                        child: Text(
                          '拍摄',
                          style: TextStyle(
                              fontSize: ScreenUtil().setSp(32),
                              color: MyColours.color_353535,
                              fontWeight: FontWeight.bold),
                        ),
                      )),
                ),
                MyDivider(
                  double.infinity,
                  ScreenUtil().setWidth(2),
                  color: MyColours.color_EEEEEE,
                ),
                InkWell(
                  onTap: () {
                    // Utils.getPickPermission(context, () {
                    //   // pickAsset(RequestType.image);
                    //   _getFromPictureOrCamera(
                    //       _uploadImageProvider.firstImage, ImageSource.gallery);
                    //   Navigator.pop(context);
                    // },
                    //     Platform.isAndroid
                    //         ? Permission.storage
                    //         : Permission.photos);
                    Utils.getPickPermission(context, () {
                      _getFromPictureOrCamera(
                          _uploadImageProvider.firstImage, ImageSource.gallery);
                      Navigator.pop(context);
                    },
                        Platform.isAndroid
                            ? Permission.storage
                            : Permission.photos);
                  },
                  child: Container(
                      width: double.infinity,
                      height: ScreenUtil().setWidth(58 * 2),
                      child: Center(
                        child: Text(
                          '从相册选择',
                          style: TextStyle(
                              fontSize: ScreenUtil().setSp(32),
                              color: MyColours.color_353535,
                              fontWeight: FontWeight.bold),
                        ),
                      )),
                ),
                MyDivider(
                  double.infinity,
                  ScreenUtil().setWidth(10),
                  color: MyColours.color_EEEEEE,
                ),
                InkWell(
                    onTap: () {
                      Navigator.pop(context, '取消');
                    },
                    child: Container(
                        width: double.infinity,
                        height: ScreenUtil().setWidth(58 * 2),
                        child: Center(
                          child: Text(
                            '取消',
                            style: TextStyle(
                                fontSize: ScreenUtil().setSp(32),
                                color: MyColours.color_353535,
                                fontWeight: FontWeight.bold),
                          ),
                        )))
              ],
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    _uploadImageProvider =
        Provider.of<UploadImageProvider>(context, listen: true);
    return Scaffold(
        backgroundColor: MyColours.color_ffffff,
        appBar: SystemAppBar('自定义图文'),
        body: SingleChildScrollView(
            controller: controller,
            child: Column(
              children: [
                Container(
                  padding:
                      EdgeInsets.symmetric(horizontal: w(16), vertical: w(12)),
                  child: Row(
                    children: [
                      Text(
                        '区域标题',
                        style: TextStyle(
                            color: MyColours.color_515151, fontSize: font(16)),
                      ),
                      // HEmptyView(44),

                      Expanded(
                          child: Container(
                        height: w(24),
                        // color: Colors.red,
                        child: TextField(
                            controller: titleC,
                            textAlign: TextAlign.right,
                            // focusNode: _cusdemNode,
                            style: TextStyle(
                              color: MyColours.color_515151,
                              fontSize: ScreenUtil().setSp(32),
                              // textBaseline: TextBaseline.alphabetic
                            ),
                            // textAlignVertical: TextAlignVertical.center,
                            maxLines: 1,
                            // inputFormatters: [
                            //   LengthLimitingTextInputFormatter(10), // 设置输入长度限制
                            // ],
                            decoration: InputDecoration(
                              hintText: "点击输入区域标题(不超过10个字)",
                              hintStyle: TextStyle(
                                color: MyColours.color_999999,
                                fontSize: ScreenUtil().setSp(32),
                              ),
                              contentPadding: EdgeInsets.zero,
                              border: OutlineInputBorder(
                                  borderSide: BorderSide.none),
                            ),
                            keyboardType: TextInputType.text,
                            onChanged: (value) {}),
                      ))
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(left: w(16)),
                  child: MyDivider(
                    double.infinity,
                    w(0.5),
                    color: MyColours.color_E7E7E7,
                  ),
                ),
                // Expanded(
                // child:
                Padding(
                    padding: EdgeInsets.symmetric(
                        // horizontal: ScreenUtil().setWidth(32),
                        vertical: ScreenUtil().setWidth(26)),
                    child: ReorderableListView(
                      shrinkWrap: true,
                      scrollController: controller,
                      children: <Widget>[
                        for (AdditionModel item in data)
                          item.type == '1'
                              ? Container(
                                  key: ValueKey(item),
                                  child: InkWell(
                                      onTap: () {
                                        double process;
                                        String qiniuUrl;
                                        List<String> tempList = [];
                                        // if (title == '头像') {
                                        process = item.image.process;
                                        qiniuUrl = item.image.qiniuUrl;
                                        // } else {
                                        //   process = _uploadImageProvider.erweima.process;
                                        //   qiniuUrl = _uploadImageProvider.erweima.qiniuUrl;
                                        // }

                                        if (qiniuUrl != null &&
                                            qiniuUrl != '') {
                                          // tempList.add(qiniuUrl);

                                          // ///没有上传完成的不可以点击
                                          // _showPhotoView(context, 0, tempList);

                                          // _uploadImageProvider.firstImage.qiniuUrl = null;
                                          // _uploadImageProvider.firstImage.process = 0;
                                          // setState(() {});
                                          _openModalBottomSheet(context);
                                          // Utils.getPickPermission(context, () {
                                          //   _getFromPictureOrCamera(
                                          //       _uploadImageProvider.firstImage,
                                          //       ImageSource.gallery);
                                          // },
                                          //     Platform.isAndroid
                                          //         ? Permission.storage
                                          //         : Permission.photos);
                                        }
                                      },
                                      child: Stack(
                                          alignment: Alignment.bottomCenter,
                                          children: [
                                            Stack(
                                                clipBehavior: Clip.none,
                                                children: [
                                                  item.image.qiniuUrl != null &&
                                                          item.image.qiniuUrl !=
                                                              ''
                                                      ? Image.network(
                                                          item.image.qiniuUrl,
                                                          fit: BoxFit.contain,
                                                          width:
                                                              double.infinity,
                                                          // width: ScreenUtil()
                                                          //     .setWidth(imgSize * 2),
                                                          // height: ScreenUtil().setWidth(
                                                          //     _uploadImageProvider
                                                          //             .imgSizefirstImage *
                                                          //         2),
                                                        )
                                                      : Image.file(
                                                          item.image.file,
                                                          fit: BoxFit.contain,
                                                          width:
                                                              double.infinity,
                                                          // width: ScreenUtil()
                                                          //     .setWidth(imgSize * 2),
                                                          // height: ScreenUtil().setWidth(
                                                          //     _uploadImageProvider
                                                          //             .imgSizefirstImage *
                                                          //         2),
                                                        ),
                                                  Positioned(
                                                      left: 0,
                                                      top: 0,
                                                      child: (item.image.file !=
                                                                  null) &&
                                                              item.image
                                                                      .process !=
                                                                  1 &&
                                                              item.image
                                                                      .process !=
                                                                  0.01
                                                          ? Container(
                                                              width: ScreenUtil()
                                                                  .screenWidth,
                                                              height: w(
                                                                  _uploadImageProvider
                                                                      .imgSizefirstImage),
                                                              color: MyColours
                                                                  .color_4D000000,
                                                              child: Center(
                                                                child: Text(
                                                                    '上传中',
                                                                    style: TextStyle(
                                                                        color: MyColours
                                                                            .color_F8F9FD)),
                                                              ),
                                                            )
                                                          : Container()),
                                                ]),
                                            // item.image.process == 1
                                            //     ? Container(
                                            //         width: w(150),
                                            //         height: w(30),
                                            //         color: MyColours.color_4D000000,
                                            //         alignment: Alignment.center,
                                            //         child: Text(
                                            //           '点击图片可以更换',
                                            //           style: TextStyle(
                                            //               color: MyColours
                                            //                   .color_F8F9FD,
                                            //               fontSize: font(14),
                                            //               fontWeight:
                                            //                   FontWeight.bold),
                                            //         ))
                                            //     : SizedBox(),
                                            item.image.process == 1
                                                ? Positioned(
                                                    top: w(15),
                                                    right: w(15),
                                                    child: InkWell(
                                                        onTap: () {
                                                          data.remove(item);
                                                          setState(() {});
                                                        },
                                                        child: Container(
                                                            width: w(30),
                                                            height: w(30),
                                                            color: Colors
                                                                .transparent,
                                                            alignment: Alignment
                                                                .center,
                                                            child: Image.asset(
                                                                Utils.getImgPath(
                                                                    'add_close')))))
                                                : SizedBox(),
                                          ])))
                              : Container(
                                  key: ValueKey(item),
                                  decoration: BoxDecoration(
                                      border: Border.all(
                                          width: w(1),
                                          color: MyColours.color_DBDBDB)),
                                  // child: Text(item.content),

                                  // color: Colors.red,
                                  child: Stack(
                                    children: [
                                      Container(
                                          // height: w(152),
                                          decoration: BoxDecoration(
                                              borderRadius:
                                                  BorderRadius.circular(r(5)),
                                              border: Border.all(
                                                  width: w(1),
                                                  color:
                                                      MyColours.color_DBDBDB)),
                                          margin: EdgeInsets.only(
                                              left: w(10),
                                              top: w(10),
                                              bottom: w(10),
                                              right: w(60)),
                                          padding: EdgeInsets.only(
                                              top: w(16),
                                              bottom: w(16),
                                              left: w(14),
                                              right: w(10)),
                                          child: TextField(
                                              controller: item.infoC,
                                              // textAlign: TextAlign.right,
                                              // focusNode: _cusdemNode,
                                              style: TextStyle(
                                                color: MyColours.color_515151,
                                                fontSize:
                                                    ScreenUtil().setSp(28),
                                                // textBaseline: TextBaseline.alphabetic
                                              ),
                                              // textAlignVertical: TextAlignVertical.center,
                                              maxLines: 5,
                                              maxLength: 50,
                                              // inputFormatters: [
                                              //   LengthLimitingTextInputFormatter(10), // 设置输入长度限制
                                              // ],
                                              decoration: InputDecoration(
                                                hintText: "点击录入文字",
                                                hintStyle: TextStyle(
                                                  color: MyColours.color_999999,
                                                  fontSize:
                                                      ScreenUtil().setSp(28),
                                                ),
                                                contentPadding: EdgeInsets.zero,
                                                border: OutlineInputBorder(
                                                    borderSide:
                                                        BorderSide.none),
                                              ),
                                              keyboardType: TextInputType.text,
                                              onChanged: (value) {})),
                                      Positioned(
                                          top: w(10),
                                          right: w(10),
                                          child: InkWell(
                                              onTap: () {
                                                data.remove(item);
                                                setState(() {});
                                              },
                                              child: Container(
                                                  width: w(30),
                                                  height: w(30),
                                                  color: Colors.transparent,
                                                  alignment: Alignment.center,
                                                  child: Image.asset(
                                                      Utils.getImgPath(
                                                          'add_close_b')))))
                                    ],
                                  ),
                                ),
                      ],
                      onReorder: (int oldIndex, int newIndex) async {
                        // if (oldIndex < newIndex) {
                        //   newIndex -= 1;
                        // }

                        // var childold = tableManagerModel.areas[oldIndex];
                        // Map<String, String> params = {
                        //   'sid': Provider.of<UserModel>(context, listen: false)
                        //       .user
                        //       .sellerid,
                        //   'regionid': childold.rid,
                        //   'order_o': tableManagerModel.areas[newIndex].orderId,
                        //   'sort': oldIndex < newIndex ? '2' : '1'
                        // };
                        // var child = tableManagerModel.areas.removeAt(oldIndex);
                        // tableManagerModel.areas.insert(newIndex, child);
                        // setState(() {});
                        // await tableManagerModel.sortByRegion(context, params);
                        // //刷新前一页数据
                        // bus.emit('refresh_table_area');
                      },
                    )),
                Container(
                  padding: EdgeInsets.only(top: w(15)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      InkWell(
                          onTap: () {
                            AdditionModel additionModel = AdditionModel();
                            additionModel.content =
                                'https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641';
                            additionModel.type = '1';
                            additionModel.order = 0;
                            additionModel.image = UploadImgModel();
                            additionModel.image.process = 1;
                            additionModel.image.qiniuUrl =
                                'https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641';

                            data.add(additionModel);
                            setState(() {});
                          },
                          child: Container(
                            width: w(77),
                            height: w(34),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(r(5)),
                                border: Border.all(
                                    width: w(1),
                                    color: MyColours.color_438E93)),
                            child: Text(
                              '+图片',
                              style: TextStyle(
                                  color: MyColours.color_000000,
                                  fontSize: font(14)),
                            ),
                          )),
                      HEmptyView(20),
                      InkWell(
                          onTap: () {
                            AdditionModel additionModel1 = AdditionModel();
                            additionModel1.content =
                                'webenkjfkdfjakdfjaldfkjaldfjaldf';
                            additionModel1.type = '2';
                            additionModel1.order = 1;

                            data.add(additionModel1);
                            setState(() {});
                          },
                          child: Container(
                            width: w(77),
                            height: w(34),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(r(5)),
                                border: Border.all(
                                    width: w(1),
                                    color: MyColours.color_438E93)),
                            child: Text(
                              '+文字',
                              style: TextStyle(
                                  color: MyColours.color_000000,
                                  fontSize: font(14)),
                            ),
                          )),
                    ],
                  ),
                )
                // )
              ],
            )));
  }
}