如何使用 Flutter 获取其他应用程序的屏幕时间(或花费的时间)?

问题描述 投票:0回答:1

我正在尝试在我的 flutter 应用程序中获取其他应用程序的屏幕时间。为此,我使用了以下软件包: 设备应用程序:^2.2.0 应用程序使用情况:^2.1.1 使用情况统计:^1.2.0

但是我在快照中获取的数据中找不到屏幕时间,所以我想知道如何获取屏幕时间(使用时间[例如今天使用 Instagram 15 分钟]):



class ScreenTime extends StatefulWidget {
  final String title;
  const ScreenTime({Key? key, required this.title}) : super(key: key);

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

class _ScreenTimeState extends State<ScreenTime> {
  // Future<List<Application>> apps = DeviceApps.getInstalledApplications(includeSystemApps: false);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          // leading: new IconButton(
          //   icon: new Icon(Icons.menu, color: Colors.white),
          //   onPressed: () {},
          // ),
        ),
        // ),

        body: Container(
            padding: EdgeInsets.all(10),
            child: ListView(children: [
              Table(
                  defaultColumnWidth: FixedColumnWidth(120.0),
                  border: TableBorder.all(
                      color: Colors.white, style: BorderStyle.solid, width: 2),
                  children: [
                    TableRow(children: [
                      Container(
                        height: 65,
                        padding: EdgeInsets.only(top: 17),
                        color: Color(0xff0307f2),
                        child: Column(
                          children: [
                            Text('App Icon',
                                style: TextStyle(
                                    fontSize: 16.0, color: Colors.white))
                          ],
                        ),
                      ),
                      Container(
                        height: 65,
                        padding: EdgeInsets.only(top: 17),
                        color: Color(0xff0307f2),
                        child: Column(children: [
                          Text('App Name',
                              style: TextStyle(
                                  fontSize: 16.0, color: Colors.white))
                        ]),
                      ),
                      Container(
                        height: 65,
                        padding: EdgeInsets.only(top: 17),
                        color: Color(0xff0307f2),
                        child: Column(children: [
                          Text(
                            'Screen Time',
                            style:
                                TextStyle(fontSize: 16.0, color: Colors.white),
                          )
                        ]),
                      ),
                    ])
                  ]),
              FutureBuilder<List>(
                  future: getApps(),
                  builder: (context, AsyncSnapshot snapshot) {
                    if (!snapshot.hasData) {
                      return Center(child: CircularProgressIndicator());
                    } else {
                      return ListView.builder(
                          controller: ScrollController(),
                          shrinkWrap: true,
                          scrollDirection: Axis.vertical,
                          itemCount: snapshot.data.length,
                          itemBuilder: (BuildContext context, int index) {
                            print('${snapshot.data[index]}' + "\n");
                            Uint8List x = snapshot.data[index].icon;
                            double st =
                                ((snapshot.data[index].updateTimeMillis) /
                                    1000);
                            return Container(
                                padding: EdgeInsets.all(5),
                                child: Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Container(
                                          height: 105,
                                          width: 125,
                                          padding: EdgeInsets.only(top: 17),
                                          color: Color(0xff0307f2),
                                          child: Column(
                                            children: [
                                              Image.memory(
                                                x,
                                                height: 50,
                                                width: 50,
                                              )
                                            ],
                                          )),
                                      Flexible(
                                        child: Container(
                                            margin: EdgeInsets.all(3),
                                            color: Color(0xff9799fc),
                                            height: 105,
                                            width: 130,
                                            padding: EdgeInsets.all(20),
                                            child: Text(
                                                '${snapshot.data[index].appName}',
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    fontSize: 20.0,
                                                    color: Colors.black))),
                                      ),
                                      Flexible(
                                        child: Container(
                                            margin: EdgeInsets.all(3),
                                            color: Color(0xff9799fc),
                                            height: 105,
                                            width: 130,
                                            padding: EdgeInsets.all(20),
                                            child: Text(st.toString(),
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    fontSize: 20.0,
                                                    color: Colors.black))),
                                      )

                                      //   Container(height: 65,padding:EdgeInsets.only(
                                      //       top:17),color:Color(0xff0307f2), child:Column(children:[Text('Screen Time', style: TextStyle(fontSize: 20.0, color: Colors.white))]),),
                                      // ])

                                      // return Row(
                                      //
                                      //     children:[
                                      //        Image.memory(
                                      //            x,
                                      //          height: 50,
                                      //          width: 50,
                                      //
                                      //        ),
                                      //       Text('${snapshot.data[index]}'),]);
                                      // }
                                    ]));
                          });
                    }
                  }),
            ])));
  }

  Future<List> getApps() async {
    Future<List> x = DeviceApps.getInstalledApplications(
        includeSystemApps: true, includeAppIcons: true);
    return x;
  }
}

如何获取每个应用程序的使用时间数据?或者我需要使用其他一些软件包吗?

编辑1:我没有任何错误,我只是不知道如何访问flutter中每个应用程序的屏幕时间*当前我正在获取更新时间。 编辑2:这个应用程序适用于Android

android flutter performance
1个回答
0
投票

你找到答案了吗? 我也在研究这个问题,但我没有在任何来源上找到任何正确的例子。

© www.soinside.com 2019 - 2024. All rights reserved.