easy_church_json 0.0.1 easy_church_json: ^0.0.1 copied to clipboard
Plugin to connect to the easy church API.
import 'package:easy_church_json_example/Events.dart';
import 'package:easy_church_json_example/Notifications.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:easy_church_json/easy_church_json.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
EasyChurchJson easyChurchJson = new EasyChurchJson();
@override
void initState() {
super.initState();
initPlatformState();
// easyChurchJson.getAllChurches();
// easyChurchJson.getNotifications("5d02d9a70eabd3105808aed8");
// easyChurchJson.getEvents("5d02d9a70eabd3105808aed8");
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
// _platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.grey.shade800,
title: Text("Easy church API"),
),
SliverToBoxAdapter(
child: Text("All churches"),
),
FutureBuilder(
future: easyChurchJson.getAllChurches(),
initialData: <SingleChurch>[],
builder: ((BuildContext context,
AsyncSnapshot<List<SingleChurch>> snapshot) {
if (!snapshot.hasData) {
return SliverToBoxAdapter(child: SizedBox());
}
return SliverFixedExtentList(
delegate: SliverChildBuilderDelegate((
BuildContext context,
int index,
) {
return ListTile(
onTap: () {},
title: Text(snapshot.data[index].name),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Events(snapshot.data[index].id),
));
},
child: Text("Events"),
),
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Notifications(
snapshot.data[index].id),
));
},
child: Text("Notifications"),
),
],
),
);
}, childCount: snapshot.data.length),
itemExtent: 70.0);
})),
],
)),
);
}
}