MyCode.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/rendering.dart';
  3. import 'dart:ui';
  4. import 'dart:typed_data';
  5. import 'dart:async';
  6. import 'package:qr_flutter/qr_flutter.dart';
  7. import 'package:redux/redux.dart';
  8. import 'package:flutter_redux/flutter_redux.dart';
  9. import '../redux/AppState.dart';
  10. import '../model/UserInfo.dart';
  11. import '../widget/LinearButton.dart';
  12. import 'dart:ui' as ui;
  13. import 'dart:io';
  14. import 'package:path_provider/path_provider.dart';
  15. import '../widget/Dialog.dart';
  16. import '../net/HttpManager.dart';
  17. class MyCode extends StatefulWidget {
  18. @override
  19. MyCodeState createState() => MyCodeState();
  20. }
  21. class MyCodeState extends State<MyCode> {
  22. GlobalKey globalKey = new GlobalKey();
  23. // 截图boundary,并且返回图片的二进制数据。
  24. Future<Uint8List> _capturePng() async {
  25. RenderRepaintBoundary boundary =
  26. globalKey.currentContext.findRenderObject();
  27. ui.Image image = await boundary.toImage();
  28. // 注意:png是压缩后格式,如果需要图片的原始像素数据,请使用rawRgba
  29. ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  30. Uint8List pngBytes = byteData.buffer.asUint8List();
  31. return pngBytes;
  32. }
  33. Future<String> _capturePath(String name) async {
  34. Directory documentsDirectory = await getExternalStorageDirectory();
  35. String path = documentsDirectory.path + name;
  36. return path;
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. AppBar appbar = AppBar(title: Text('我的推广码'), centerTitle: true);
  41. double _height = MediaQuery.of(context).size.height -
  42. MediaQueryData.fromWindow(window).padding.top -
  43. appbar.preferredSize.height;
  44. return StoreConnector<AppState, UserInfo>(
  45. converter: (Store store) => store.state.userInfo,
  46. builder: (context, userInfo) {
  47. String qrstr =HttpManager.baseUrl+"share?userId=${userInfo.id}&channel=${userInfo.channel}";
  48. // final cryptor = new PlatformStringCryptor();
  49. return RepaintBoundary(
  50. key: globalKey,
  51. child: Scaffold(
  52. appBar: appbar,
  53. body: Container(
  54. color: Color(0xFF2B2B42),
  55. height: double.infinity,
  56. width: double.infinity,
  57. child: SingleChildScrollView(
  58. child: Container(
  59. height: _height - 60,
  60. constraints: BoxConstraints(minHeight: 543),
  61. margin:
  62. EdgeInsets.symmetric(vertical: 30, horizontal: 30),
  63. color: Color(0xFF363759),
  64. child: Column(
  65. mainAxisAlignment: MainAxisAlignment.center,
  66. children: <Widget>[
  67. Container(height: 36),
  68. Image.asset('images/text_yonghuduan.png'),
  69. Container(height: 25),
  70. Container(
  71. width: 150,
  72. height: 150,
  73. color: Colors.white,
  74. // padding: EdgeInsets.all(7),
  75. child: QrImage(
  76. data: qrstr,
  77. size: 150.0,
  78. ),
  79. ),
  80. Container(
  81. height: 10,
  82. ),
  83. Text(
  84. '扫一扫下载APP',
  85. style: TextStyle(
  86. color: Colors.white,
  87. fontSize: 14,
  88. fontWeight: FontWeight.w500),
  89. ),
  90. Container(
  91. margin: EdgeInsets.only(top: 30),
  92. width: 180,
  93. child: LinearButton(
  94. btntext: '立刻邀请',
  95. btnHeight: 44.0,
  96. colorList: [
  97. Color(0xFFD4504B),
  98. Color(0xFFD4504B)
  99. ],
  100. onTapHomeMenu: () async {
  101. MyDialog.showDialog(context, '手动截图立即分享二维码给小伙伴吧!');
  102. // final Io.Directory systemTempDir =
  103. // Io.Directory.systemTemp;
  104. // final Io.File file = await new Io.File(
  105. // '${systemTempDir.path}/temp.png')
  106. // .create();
  107. // print(file);
  108. // List<int> bytes = await _capturePng();
  109. // await file.writeAsBytes(bytes);
  110. // print('保存成功');
  111. },
  112. ),
  113. ),
  114. Expanded(
  115. flex: 1,
  116. child: Container(),
  117. ),
  118. Image.asset('images/img_0000.png'),
  119. ],
  120. ),
  121. ),
  122. ),
  123. )));
  124. });
  125. }
  126. }