relatica/lib/screens/home.dart

107 wiersze
3.0 KiB
Dart
Czysty Zwykły widok Historia

2022-11-09 02:28:48 +00:00
import 'package:flutter/material.dart';
2022-11-17 16:04:14 +00:00
import 'package:go_router/go_router.dart';
import 'package:logging/logging.dart';
2022-12-08 18:37:30 +00:00
import 'package:provider/provider.dart';
2022-11-09 02:28:48 +00:00
import '../controls/app_bottom_nav_bar.dart';
2022-12-08 18:37:30 +00:00
import '../controls/padding.dart';
import '../controls/timeline/timeline_panel.dart';
2022-11-17 16:04:14 +00:00
import '../models/TimelineIdentifiers.dart';
2022-12-08 18:37:30 +00:00
import '../models/group_data.dart';
import '../services/timeline_manager.dart';
2022-11-17 16:04:14 +00:00
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
2022-11-17 16:04:14 +00:00
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final _logger = Logger('$HomeScreen');
2022-11-09 02:28:48 +00:00
final postText = TextEditingController();
2022-11-17 16:04:14 +00:00
var currentType = TimelineType.home;
2022-12-08 18:37:30 +00:00
GroupData? currentGroup;
2022-11-17 16:04:14 +00:00
final types = [
2022-12-17 17:17:47 +00:00
TimelineType.self,
2022-11-17 16:04:14 +00:00
TimelineType.home,
TimelineType.global,
TimelineType.local,
2022-12-08 18:37:30 +00:00
TimelineType.group,
2022-11-17 16:04:14 +00:00
];
2022-11-09 02:28:48 +00:00
@override
Widget build(BuildContext context) {
2022-11-17 16:04:14 +00:00
_logger.finest('Build');
2022-12-08 18:37:30 +00:00
final groups = context
.watch<TimelineManager>()
.getGroups()
.getValueOrElse(() => [])
.toList();
2022-11-09 02:28:48 +00:00
return Scaffold(
appBar: AppBar(
2022-12-08 18:37:30 +00:00
backgroundColor: Theme.of(context).canvasColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
DropdownButton<TimelineType>(
value: currentType,
items: types
.map((e) => DropdownMenuItem<TimelineType>(
value: e,
child: Text(e.toLabel()),
))
.toList(),
onChanged: (value) {
setState(() {
currentType = value!;
});
}),
const HorizontalPadding(),
if (currentType == TimelineType.group)
DropdownButton<GroupData>(
value: currentGroup,
items: groups
.map((g) => DropdownMenuItem<GroupData>(
value: g,
child: Text(g.name),
))
.toList(),
onChanged: (value) {
setState(() {
currentGroup = value;
});
}),
],
),
actions: [
IconButton(
onPressed: () {
2022-11-17 16:04:14 +00:00
context.push('/post/new');
},
icon: Icon(
Icons.add,
color: Theme.of(context).primaryColor,
),
2022-11-17 16:04:14 +00:00
),
],
),
body: Column(
children: [
Expanded(
child: TimelinePanel(
timeline: TimelineIdentifiers(
timeline: currentType,
2022-12-08 18:37:30 +00:00
auxData: currentGroup?.id ?? '',
),
)),
],
2022-11-09 02:28:48 +00:00
),
bottomNavigationBar: const AppBottomNavBar(
2022-12-08 19:23:11 +00:00
currentButton: NavBarButtons.timelines,
),
2022-11-09 02:28:48 +00:00
);
}
}