| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import 'package:flutter/material.dart';
- import 'package:flutter/rendering.dart';
- import 'dart:ui';
- import 'dart:typed_data';
- import 'dart:async';
- import 'package:qr_flutter/qr_flutter.dart';
- import 'package:redux/redux.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../model/UserInfo.dart';
- import '../widget/LinearButton.dart';
- import 'dart:ui' as ui;
- import 'dart:io';
- import 'package:path_provider/path_provider.dart';
- import '../widget/Dialog.dart';
- import '../net/HttpManager.dart';
- class MyCode extends StatefulWidget {
- @override
- MyCodeState createState() => MyCodeState();
- }
- class MyCodeState extends State<MyCode> {
- GlobalKey globalKey = new GlobalKey();
- // 截图boundary,并且返回图片的二进制数据。
- Future<Uint8List> _capturePng() async {
- RenderRepaintBoundary boundary =
- globalKey.currentContext.findRenderObject();
- ui.Image image = await boundary.toImage();
- // 注意:png是压缩后格式,如果需要图片的原始像素数据,请使用rawRgba
- ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
- Uint8List pngBytes = byteData.buffer.asUint8List();
- return pngBytes;
- }
- Future<String> _capturePath(String name) async {
- Directory documentsDirectory = await getExternalStorageDirectory();
- String path = documentsDirectory.path + name;
- return path;
- }
- @override
- Widget build(BuildContext context) {
- AppBar appbar = AppBar(title: Text('我的推广码'), centerTitle: true);
- double _height = MediaQuery.of(context).size.height -
- MediaQueryData.fromWindow(window).padding.top -
- appbar.preferredSize.height;
- return StoreConnector<AppState, UserInfo>(
- converter: (Store store) => store.state.userInfo,
- builder: (context, userInfo) {
- String qrstr =HttpManager.baseUrl+"share?userId=${userInfo.id}&channel=${userInfo.channel}";
- // final cryptor = new PlatformStringCryptor();
- return RepaintBoundary(
- key: globalKey,
- child: Scaffold(
- appBar: appbar,
- body: Container(
- color: Color(0xFF2B2B42),
- height: double.infinity,
- width: double.infinity,
- child: SingleChildScrollView(
- child: Container(
- height: _height - 60,
- constraints: BoxConstraints(minHeight: 543),
- margin:
- EdgeInsets.symmetric(vertical: 30, horizontal: 30),
- color: Color(0xFF363759),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(height: 36),
- Image.asset('images/text_yonghuduan.png'),
- Container(height: 25),
- Container(
- width: 150,
- height: 150,
- color: Colors.white,
- // padding: EdgeInsets.all(7),
- child: QrImage(
- data: qrstr,
- size: 150.0,
- ),
- ),
- Container(
- height: 10,
- ),
- Text(
- '扫一扫下载APP',
- style: TextStyle(
- color: Colors.white,
- fontSize: 14,
- fontWeight: FontWeight.w500),
- ),
- Container(
- margin: EdgeInsets.only(top: 30),
- width: 180,
- child: LinearButton(
- btntext: '立刻邀请',
- btnHeight: 44.0,
- colorList: [
- Color(0xFFD4504B),
- Color(0xFFD4504B)
- ],
- onTapHomeMenu: () async {
- MyDialog.showDialog(context, '手动截图立即分享二维码给小伙伴吧!');
- // final Io.Directory systemTempDir =
- // Io.Directory.systemTemp;
- // final Io.File file = await new Io.File(
- // '${systemTempDir.path}/temp.png')
- // .create();
- // print(file);
- // List<int> bytes = await _capturePng();
- // await file.writeAsBytes(bytes);
- // print('保存成功');
- },
- ),
- ),
- Expanded(
- flex: 1,
- child: Container(),
- ),
- Image.asset('images/img_0000.png'),
- ],
- ),
- ),
- ),
- )));
- });
- }
- }
|