This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| // As login page has to handle user input, it has to be stateful | |
| class TODOLogin extends StatefulWidget { | |
| // Callback function that will be called on pressing the login button | |
| final onLogin; | |
| TODOLogin({@required this.onLogin}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:firebase_auth/firebase_auth.dart'; | |
| class Authentication { | |
| final _firebaseAuth = FirebaseAuth.instance; | |
| Future<FirebaseUser> login(String email, String password) async { | |
| try { | |
| AuthResult result = await _firebaseAuth.signInWithEmailAndPassword( | |
| email: email, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Importing firestore package | |
| import 'package:cloud_firestore/cloud_firestore.dart'; | |
| import 'package:flutter/material.dart'; | |
| class TODOList extends StatelessWidget { | |
| // Setting reference to 'tasks' collection | |
| final collection = Firestore.instance.collection('tasks'); | |
| @override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:cloud_firestore/cloud_firestore.dart'; | |
| import 'package:flutter/material.dart'; | |
| class TODOCreate extends StatefulWidget { | |
| @override | |
| State<StatefulWidget> createState() { | |
| return TODOCreateState(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:http/http.dart' as http; | |
| // Sending a GET request | |
| const url = 'http://some-api.com/users'; | |
| const response = await http.get(url); | |
| print(response.body); | |
| // Sending a GET request using .read | |
| const data = await http.read(url); | |
| print(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:http/http.dart' as http; | |
| // Sending a POST request | |
| const url = 'https://some-api.com/users'; | |
| const payload = {online: false}; | |
| const response = await http.post(url, body: payload); | |
| print(response.statusCode); // 200 | |
| // Sending a POST request with headers | |
| const headers = {'Content-Type': 'application/json'}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:http/http.dart' as http; | |
| // Create a client instance | |
| const client = http.Client(); | |
| // Making first request | |
| const first_response = await client.read('https://some-api.com/data'); | |
| print(first_response); | |
| // Second request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('Mock functions', () => { | |
| it('can create mock functions', () => { | |
| const fn = jest.fn(); | |
| fn.mockReturnValueOnce(5); | |
| const result = fn(10); | |
| expect(result).toBe(5); // TRUE | |
| expect(fn).toHaveBeenCalled(); // TRUE | |
| expect(fn).toHaveBeenCalledWith(10); // TRUE | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios from 'axios'; // HTTP library | |
| import store from './store'; // Redux store | |
| export const get_data = () => { | |
| const state = store.getState(); | |
| const {token} = state; | |
| return axios({ | |
| url: 'https://some-url.com/api', | |
| method: 'get', | |
| headers: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const do_stuff = () => { | |
| console.error('Cannot do stuff!'); | |
| }; |