Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/parse yaml #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx4g
117 changes: 71 additions & 46 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import 'dart:async';
import 'dart:io';
import 'package:path_provider/path_provider.dart';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:yaml/yaml.dart';

void main() => runApp(MyApp());

Expand All @@ -20,7 +26,7 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
home: MyHomePage(title: 'DevFest'),
);
}
}
Expand All @@ -44,17 +50,18 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
static var httpClient = new HttpClient();

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
Future<dynamic> _downloadFile(String url, String filename) async {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
var content = await readFile(file);
var doc = loadYaml(content);
return doc;
}

@override
Expand All @@ -71,41 +78,59 @@ class _MyHomePageState extends State<MyHomePage> {
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
body: FutureBuilder(
future: _downloadFile(
"https://raw.githubusercontent.com/GDG-Zagreb/zeppelin/gh-pages/_data/sessions.yml",
"sessions.yml"),
builder: (context, response) {
print(response.data);
return ListView.builder(
itemCount: response.data.length,
itemBuilder: (context, index) {
var item = response.data[index];
String subtype = item["subtype"];
String complexity = item["complexity"];
var color;
switch (complexity) {
case "Beginner":
color = Colors.green[800];
break;
case "Intermediate":
color = Colors.yellow[800];
break;
default:
color = Colors.blue[800];
break;
}
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Text(item["title"]),
)),
]),
subtitle: Text(
item["description"] != null
? item["description"]
: '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
trailing: Icon(Icons.hearing, color: color),
onTap: () {
print(item["title"]);
},
);
});
}),
);
}

Future<String> readFile(File stored) async {
String contents = await stored.readAsString();
return contents;
}
}
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
path_provider: ^0.5.0
yaml: ^2.1.15

dev_dependencies:
flutter_test:
Expand Down