2024-09-11 20:15:53 +00:00
|
|
|
import 'package:finnow_app/auth/model.dart';
|
2024-09-19 19:12:23 +00:00
|
|
|
import 'package:finnow_app/components/profile_list_item.dart';
|
2024-09-11 20:15:53 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-09-19 19:12:23 +00:00
|
|
|
import '../api/profile.dart';
|
|
|
|
import '../main.dart';
|
2024-09-11 20:15:53 +00:00
|
|
|
|
|
|
|
class ProfilesPage extends StatelessWidget {
|
|
|
|
const ProfilesPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: const Padding(
|
2024-09-19 19:12:23 +00:00
|
|
|
padding: EdgeInsets.all(10),
|
2024-09-11 20:15:53 +00:00
|
|
|
child: Column(children: [
|
2024-09-19 19:12:23 +00:00
|
|
|
Text('Select a Profile', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 32.0)),
|
2024-09-11 20:15:53 +00:00
|
|
|
SizedBox(height: 10),
|
|
|
|
Expanded(child: _ProfilesListView()),
|
|
|
|
])),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () => print('pressed'),
|
|
|
|
child: const Icon(Icons.add)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProfilesListView extends StatefulWidget {
|
|
|
|
const _ProfilesListView();
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_ProfilesListView> createState() => __ProfilesListViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class __ProfilesListViewState extends State<_ProfilesListView> {
|
|
|
|
List<Profile> profiles = List.empty();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListView(
|
|
|
|
scrollDirection: Axis.vertical,
|
2024-09-19 19:12:23 +00:00
|
|
|
children: profiles.map(ProfileListItem.new).toList(),
|
2024-09-11 20:15:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
refreshProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
void refreshProfiles() async {
|
|
|
|
setState(() => profiles = List.empty());
|
|
|
|
final authState = getIt<AuthenticationModel>().state;
|
|
|
|
if (authState is Authenticated) {
|
|
|
|
final List<Profile> latestProfiles = await getProfiles(authState.token);
|
|
|
|
setState(() => profiles = latestProfiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|