2022-04-30 18:47:48 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
|
|
|
import 'package:nekoya_flutter/components/session_box.dart';
|
2022-05-12 16:47:18 +02:00
|
|
|
import 'package:nekoya_flutter/data/auth.dart';
|
2022-04-30 18:47:48 +02:00
|
|
|
|
|
|
|
class Sessions extends StatefulWidget {
|
|
|
|
const Sessions({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Sessions> createState() => _SessionsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SessionsState extends State<Sessions> {
|
2022-05-12 16:47:18 +02:00
|
|
|
var session = '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
getSession().then((session) async {
|
|
|
|
session = session;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-30 18:47:48 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Active Sessions'),
|
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: const Color(0xff212226),
|
|
|
|
),
|
|
|
|
body: FutureBuilder<dynamic>(
|
2022-05-12 16:47:18 +02:00
|
|
|
future: getSessions(session),
|
2022-04-30 18:47:48 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
2022-05-12 16:47:18 +02:00
|
|
|
var listSessions = snapshot.data;
|
2022-04-30 18:47:48 +02:00
|
|
|
return ListView.builder(
|
2022-05-12 16:47:18 +02:00
|
|
|
itemCount: listSessions['data']!.length,
|
2022-04-30 18:47:48 +02:00
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return SessionBox(
|
|
|
|
icon: const Icon(Icons.key, color: Colors.white, size: 50,),
|
2022-05-12 16:47:18 +02:00
|
|
|
ip: listSessions['data'][index]['ip'].split(', ')[0],
|
|
|
|
userAgent: listSessions['data'][index]['user_agent'],
|
2022-04-30 18:47:48 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: Color(0xff8B0000),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|