Skip to content

Instantly share code, notes, and snippets.

View timbergus's full-sized avatar

Gustavo Muñoz timbergus

View GitHub Profile
@timbergus
timbergus / login.dart
Created April 3, 2019 13:15
flutter_login_form
import 'package:flutter/material.dart';
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
String _email;
String _password;
import 'package:flutter/material.dart';
import 'package:flutter_app/login.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
import React, { Component, createRef } from 'react';
export default class CMP extends Component {
constructor(props) {
super(props);
this.refA = createRef();
this.refB = createRef();
}
render() {
final _loginFormKey = GlobalKey<FormState>();
// This method call the functions in our component's
// validator property.
_loginFormKey.currentState.validate();
// This method call the functions in our component's
// onSaved method.
final _loginFormKey = GlobalKey<FormState>();
// This method call the functions in our component's
// validator property.
_loginFormKey.currentState.validate();
// This method call the functions in our component's
// onSaved method.
TextFormField(
validator: (val) {
if (val.isEmpty) {
return 'You must enter a valid email!';
}
return null;
},
onSaved: (val) => _email = val,
),
RaisedButton(
child: Text('Login'),
onPressed: () {
if (_loginFormKey.currentState.validate()) {
_loginFormKey.currentState.save();
print('Email: $_email, password: $_password');
}
},
),
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Weather App',
home: MyHomePage(),
import 'package:geolocator/geolocator.dart';
class _MyHomePageState extends State<MyHomePage> {
[...]
Future<Position> getPosition() async {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
return position;
import 'package:geolocator/geolocator.dart';
class _MyHomePageState extends State<MyHomePage> {
[...]
String _locality = '';
Future<Placemark> getPlacemark(double latitude, double longitude) async {
List<Placemark> placemark = await Geolocator()