2019-11-18

2019-11-18  本文已影响0人  xiezefeng

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// import 'package:app_flutter/Tool/DataSort.dart';

class BusinessInformation extends StatefulWidget {
BusinessInformation({Key key}) : super(key: key);

_BusinessInformationState createState() => _BusinessInformationState();
}

class _BusinessInformationState extends State<BusinessInformation> {
@override
void initState() {
super.initState();

_iOSPushToVC2().then((onValue) {
  setState(() {
    this.infoData = onValue;
  });
});

}

// 创建一个给native的channel (类似iOS的通知)
static const methodChannel = const MethodChannel('com.pages.your/native_get');
Map infoData = {};

_iOSPushToVC() async {
await methodChannel.invokeMethod('iOSFlutter', '参数');
}

Future<dynamic> _iOSPushToVC2() async {
try {
return await methodChannel.invokeMethod('iOSFlutter2');
} on PlatformException {
return "error";
}
}

@override
Widget build(BuildContext context) {
if (infoData == null || infoData.length <= 0) {
return Scaffold(
appBar: AppBar(title: Text("")),
body: Text(""),
);
}

List list = this.infoData["dataSource"];
var titleName = this.infoData['merchantName'];
var logoImage = this.infoData['logoImage'];

// Map map = {
//   'name': "zefneg",
//   'nickname': "ffff",
//   'sessionKey': '2389248',
//   'array': ['xx', 'ff'],
//   'dic': {'zz': 'fff'},
// };

print(this.infoData);

return Scaffold(
    appBar: AppBar(
      title: Text(this.infoData["titleName"],
          style: TextStyle(
            color: Colors.black,
          )),
      backgroundColor: Colors.white,
      centerTitle: true,
      leading: new GestureDetector(
          onTap: () {
            _iOSPushToVC();
          },
          child: Image(
            image: new AssetImage("images/ic_top_back_press.png"),
          )),
    ),
    body:
        // Text(dataSort(map)));

        Container(
      color: Colors.white,
      child: Column(
        children: <Widget>[
          UnitInfo(list, titleName, logoImage),
        ],
      ),
    ));

}

// }
}

class UnitInfo extends StatelessWidget {
// const UnitInfo({Key key}) : super(key: key);
// String titleString;
// String detailString;
List dataSource;
var logoImage = '';
var businessName;

UnitInfo(this.dataSource, this.businessName, this.logoImage);

Color hexToColor(String s) {
// 如果传入的十六进制颜色值不符合要求,返回默认值
if (s == null ||
s.length != 7 ||
int.tryParse(s.substring(1, 7), radix: 16) == null) {
s = '#999999';
}

return new Color(int.parse(s.substring(1, 7), radix: 16) + 0xFF000000);

}

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.fromLTRB(10, 0, 0, 0),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - 88,
child: ListView.builder(
// padding: EdgeInsets.fromLTRB(0, 15, 15, 15),
itemCount: this.dataSource.length + 1,

    itemBuilder: (context, index) {
      if (index == 0) {
        return Column(
          // mainAxisAlignment: MainAxisAlignment.start,
          //  verticalDirection: VerticalDirection.down,
          children: <Widget>[
            SizedBox(height: 30),
            Container(
              width: 60,
              height: 60,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(30),
                image: DecorationImage(
                  image: NetworkImage(logoImage == null ? '' : logoImage),
                  fit: BoxFit.cover,
                ),
              ),
            ),
            SizedBox(height: 10),
            Container(
              child: Text(businessName),
            ),
            SizedBox(height: 60),
          ],
        );
      }
      Map unitMap = this.dataSource[index - 1];
      return Row(
        textBaseline: TextBaseline.alphabetic,
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
            alignment: Alignment.topLeft,
            // margin: EdgeInsets.fromLTRB(left, top, right, bottom),
            width: 200,
            child: Text(
              unitMap["name"],
              style: TextStyle(
                  fontSize: 15,
                  color: hexToColor("#ACAFB8"),
                  decoration: TextDecoration.none),
              textAlign: TextAlign.left,
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 15, 0),
            child: Text(
              unitMap["detail"],
              textAlign: TextAlign.right,
              style: TextStyle(
                  fontSize: 15,
                  color: hexToColor("#222847"),
                  decoration: TextDecoration.none),
            ),
          ),
        ],
      );
    },
  ),
);

}
}

上一篇 下一篇

猜你喜欢

热点阅读