Skip to content

Commit

Permalink
feat: add agenda-page
Browse files Browse the repository at this point in the history
  • Loading branch information
slightfoot committed Oct 7, 2023
1 parent 7b66fe3 commit c0da583
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutteristas/layout/page_frame.dart';
import 'package:flutteristas/pages/agenda_page.dart';
import 'package:flutteristas/pages/column2_page.dart';
import 'package:flutteristas/pages/column3_page.dart';
import 'package:flutteristas/pages/contact_us_page.dart';
Expand All @@ -16,6 +17,7 @@ import 'package:jaspr_router/jaspr_router.dart';

final routes = [
WelcomePage.route,
AgendaPage.route,
TwoSectionPage.route,
Column2Page.route,
Column3Page.route,
Expand Down
124 changes: 124 additions & 0 deletions lib/pages/agenda_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import 'dart:convert';
import 'dart:html';

import 'package:intl/intl.dart';
import 'package:jaspr/components.dart';
import 'package:jaspr/html.dart';
import 'package:jaspr_router/jaspr_router.dart';
import 'package:http/http.dart' as http;

class AgendaPage extends StatelessComponent {
const AgendaPage({super.key});

static final route = Route(
path: '/agenda',
title: 'Agenda',
builder: (context, state) => AgendaPage(),
);

@override
Iterable<Component> build(BuildContext context) sync* {
yield AgendaTalkList(
projectId: 'flutteristas-website-dev-default-rtdb',
);
}
}

class AgendaTalkList extends StatefulComponent {
const AgendaTalkList({
super.key,
required this.projectId,
});

final String projectId;

@override
State<AgendaTalkList> createState() => _AgendaState();
}

class _AgendaState extends State<AgendaTalkList> {
late Future<List<AgendaItem>> _futureAgendaItems;

@override
void initState() {
super.initState();
_futureAgendaItems = fetchAgenda();
}

Future<List<AgendaItem>> fetchAgenda() async {
// see: https://firebase.google.com/docs/reference/rest/database
final url = "https://${component.projectId}.firebaseio.com/conference_agenda.json";
final resp = await http.get(Uri.parse(url));
final data = json.decode(resp.body);
return [
...(data as List) //
.cast<Map<String, dynamic>>()
.map(AgendaItem.fromJson),
];
}

@override
Iterable<Component> build(BuildContext context) sync* {
yield FutureBuilder<List<AgendaItem>>(
initialData: <AgendaItem>[],
future: _futureAgendaItems,
builder: (BuildContext context, AsyncSnapshot<List<AgendaItem>> snapshot) sync* {
for (final (index, item) in snapshot.requireData.indexed) {
yield div(
id: 'item-$index',
styles: Styles.box(
border: Border.all(
BorderSide(
style: BorderStyle.solid,
color: Colors.purple,
width: Unit.pixels(1),
),
),
padding: EdgeInsets.all(Unit.em(0.5)),
margin: EdgeInsets.only(bottom: Unit.em(1.0)),
),
[
p(
[
text('Title:'),
strong([text(item.title)]),
br(),
text(item.description),
br(),
text(
'On at: '
'${DateFormat.Hms().format(item.time)} on '
'${DateFormat.yMMMd().format(item.time)}',
),
],
),
],
);
}
},
);
}
}

class AgendaItem {
const AgendaItem({
required this.title,
required this.description,
required this.time,
});

final String title;
final String description;
final DateTime time;

static AgendaItem fromJson(Map<String, dynamic> json) {
return AgendaItem(
title: json['title'] as String,
description: json['description'] as String,
time: DateTime.parse(json['time'] as String),
);
}

@override
String toString() => 'AgendaItem{$title, $time}';
}
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ environment:
sdk: ^3.1.0

dependencies:
firebase_dart: ^1.0.11
firebase_core: ^2.15.0
firebase_database: ^10.2.5
jaspr: ^0.9.0
jaspr_router: ^0.3.0
http: ^1.1.0
intl: ^0.18.1

dev_dependencies:
build_runner: ^2.4.6
Expand Down

0 comments on commit c0da583

Please sign in to comment.