Skip to content

Instantly share code, notes, and snippets.

View asialgearoid's full-sized avatar

asialgearoid

  • Tokyo, Japan
View GitHub Profile
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:32
Flutter Todo App Final Code
// Import MaterialApp and other widgets which we can use to quickly create a material app
import 'package:flutter/material.dart';
// Code written in Dart starts exectuting from the main function. runApp is part of
// Flutter, and requires the component which will be our app's container. In Flutter,
// every component is known as a "widget".
void main() => runApp(new TodoApp());
// Every component in Flutter is a widget, even the whole app itself
class TodoApp extends StatelessWidget {
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:21
Todo App Step 5 (Removing an Item)
// Much like _addTodoItem, this modifies the array of todo strings and
// notifies the app that the state has changed by using setState
void _removeTodoItem(int index) {
setState(() => _todoItems.removeAt(index));
}
// Show an alert dialog asking the user to confirm that the task is done
void _promptRemoveTodoItem(int index) {
showDialog(
context: context,
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:20
Todo App Step 4 (User Interaction)
// Instead of autogenerating a todo item, _addTodoItem now accepts a string
void _addTodoItem(String task) {
// Only add the task if the user actually entered something
if(task.length > 0) {
setState(() => _todoItems.add(task));
}
}
Widget build(BuildContext context) {
return new Scaffold(
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:19
Todo App Step 3 (Modifying State)
class TodoListState extends State<TodoList> {
List<String> _todoItems = [];
// This will be called each time the + button is pressed
void _addTodoItem() {
// Putting our code inside "setState" tells the app that our state has changed, and
// it will automatically re-render the list
setState(() {
int index = _todoItems.length;
_todoItems.add('Item ' + index.toString());
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:18
Todo App Step 2 (Stateful)
// Import MaterialApp and other widgets which we can use to quickly create a material app
import 'package:flutter/material.dart';
void main() => runApp(new TodoApp());
class TodoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Todo List',
@asialgearoid
asialgearoid / main.dart
Created May 30, 2018 03:17
Todo App Step 1
// Import MaterialApp and other widgets which we can use to quickly create a material app
import 'package:flutter/material.dart';
// Code written in Dart starts exectuting from the main function. runApp is part of
// Flutter, and requires the component which will be our app's container. In Flutter,
// every component is known as a "widget".
void main() => runApp(new TodoApp());
// Every component in Flutter is a widget, even the whole app itself
class TodoApp extends StatelessWidget {
@asialgearoid
asialgearoid / screenshots.js
Created March 12, 2018 03:01
Testing Cordova Apps with Appium (screenshots.js)
const fs = require('fs');
describe('Screenshots', () => {
it('shows text is visible', () => {
browser.timeouts('implicit', 5000);
// We need to switch to the native context for the screenshot to work
browser.context('NATIVE_APP');
// browser.screenshot returns the screenshot as a base64 string
@asialgearoid
asialgearoid / wdio.conf.js
Created March 12, 2018 02:03
Testing Cordova Apps with Appium (wdio.conf.js)
exports.config = {
// 4723 is the default port for Appium
port: 4723,
// How much detail should be logged. The options are:
// 'silent', 'verbose', 'command', 'data', 'result', 'error'
logLevel: 'error',
// This defines which kind of device we want to test on, as well as how it should be
// configured.
@asialgearoid
asialgearoid / button.js
Created March 12, 2018 00:34
Testing Cordova Apps with Appium (button.js)
// tests/spec/button.js
// Note that when tests are run by webdriver.io, `browser` is a global object.
// "describe" is a wrapper used to group related tests. It makes the output from the
// test reporter much easier to read through.
describe('Toggle Button', () => {
// As the name suggests, this runs before each test. It is a good place to set
// up common settings.
beforeEach(() => {
// Wait up to 5 seconds for commands to work
@asialgearoid
asialgearoid / index.html
Created March 12, 2018 00:31
Testing Cordova Apps with Appium (index.html)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Appium Test</title>
</head>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#showHideButton').addEventListener('click', function() {