“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

Functional view

Today’s function is simple, when we click on device Info it will pop up the current device information

The source code to view

The code for today is in the flutter_ume_kit_device package, which has a folder device_info. The code is in device_info_panel.dart, which uses the official DART class package: Device_info/Device_INF O. Art, the modified class contains iOS and Android device information, takes device information by platform, reassembles deviceInfo information, and splices all information into StringBuffer


void _getDeviceInfo() async {
  DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
  Map dataMap = Map();
  if (widget.platform.isAndroid) {
    AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
    dataMap = _readAndroidBuildData(androidDeviceInfo);
  } else if (widget.platform.isIOS) {
    IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
    dataMap = _readIosDeviceInfo(iosDeviceInfo);
  }
  StringBuffer buffer = StringBuffer();
  dataMap.forEach((k, v) {
    buffer.write('$k:  $v\n');
  });
  _content = buffer.toString();
  setState(() {});
}
Copy the code

That’s the main code for today, and I won’t go into much more detail about the rest of the UI layout

StringBuffer

The StringBuffer used for info processing is familiar to Java and Android developers, but not to iOS developers

There are three types of String processing in Java: String, StringBuffer, and StringBuilder. There is no equivalent method for StringBuilder in Dart

StringBuffer is a mutable String, and any changes to String create a new object, whereas StringBuffer is a mutable String, and when you manipulate it, it doesn’t create a new object, right Object, so the method used to manipulate strings in the above method is a StringBuffer

StringBuffer buffer = StringBuffer(); dataMap.forEach((k, v) { buffer.write('$k: $v\n'); }); _content = buffer.toString();

conclusion

Well today’s source code to view this, today will be the last issue of our UME series, if there is anything to see the source code please comment below, we look at the source code, learn together

As a primary student of Flutter, I hope you can give me more advice and discuss with me if there is any problem