-1

我正在使用一个名为 Icapp_license 的插件进行颤振,它创建一个文件,其中包含您使用的插件的所有许可证,因此输出是这个文件,我想转换为 listview

生成的文件在这里链接

4

1 回答 1

0

您可以在下面复制粘贴运行完整代码
执行命令flutter packages pub run icapps_license
license.dart后将在目录中自动生成util
您可以import './util/license.dart';

代码片段

ListView.builder(
      itemCount: LicenseUtil.getLicenses().length,
      itemBuilder: (BuildContext context, int index) {
        final item = LicenseUtil.getLicenses()[index];

工作演示

在此处输入图像描述

完整代码

import 'package:flutter/material.dart';
import './util/license.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: ListView.builder(
          itemCount: LicenseUtil.getLicenses().length,
          itemBuilder: (BuildContext context, int index) {
            final item = LicenseUtil.getLicenses()[index];
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                color: Colors.grey.withOpacity(0.5),
                child: Column(
                  children: [
                    Text(item.name),
                    Text(item.version),
                    Text(item.url),
                    Container(height: 8),
                    Text(item.license),
                  ],
                ),
              ),
            );
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
于 2020-03-25T08:42:29.430 回答