Ir al contenido principal

Entradas

Mostrando entradas de agosto, 2019

Flutter / List View / Padding

Padding Padding ( padding : EdgeInsets . only (top : 15.0 , bottom : 15.0 ), child : ) List View ListView todoListItems () { return ListView . builder ( itemCount : count, itemBuilder : ( BuildContext context, int position) { return Card ( color : Colors .white, elevation : 2.0 , child : ListTile ( leading : CircleAvatar ( backgroundColor : Colors .black, child : Text ( this .todos[position].id. toString ()), ), title : Text ( this .todos[position].title), subtitle : Text ( this .todos[position].date), onTap : (){ debugPrint ( "Tapped on " + this .todos[position].id. toString () ); }, ), ); }); }

Flutter / Basic Page

Basic Page void main () => runApp ( MyApp ()); class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build ( BuildContext context) { DbHelper helper = DbHelper (); return MaterialApp ( title : 'Todos' , theme : ThemeData ( primarySwatch : Colors .blue, ), home : MyHomePage (title : 'Todos' ), ); } } class MyHomePage extends StatefulWidget { MyHomePage ({ Key key, this .title}) : super (key : key); final String title; @override _MyHomePageState createState () => _MyHomePageState (); } class _MyHomePageState extends State < MyHomePage > { @override Widget build ( BuildContext context) { return new Scaffold ( appBar : new AppBar ( title : new Text (widget.title), ), body : TodoList (), ); } }

Flutter / SQL / Singleton / Threads

SQL In pubspec.yaml add Add dependencies dependencies : flutter : sdk : flutter sqflite : any path_provider : any intl : ^0.15.7 ^ Means above or equal to that version SINGLETON class DbHelper { static final DbHelper _dbHelper = DbHelper . _internal (); DbHelper . _internal (); factory DbHelper (){ return _dbHelper; } } Threads Can be used with Futures or Sync & Wait Initialize a DB import 'package:sqflite/sqflite.dart' ; import 'dart:async' ; import 'dart:io' ; import 'package:path_provider/path_provider.dart' ; static Database _db; Future < Database > get db async { if (_db == null ) { _db = await initializeDb (); } return _db; } Future < Database > initializeDb () async { Directory dir = await getApplicationDocumentsDirectory (); String path = dir.path + "todos.db" ; var dbTodos = await openDatabase (path, ...

Flutter / Model class

Constructor Can be many class Todo { int _id; String _title; String _descrition; String _date; int _priority; Todo ( this ._title, this ._priority, this ._date, [ this ._descrition]); Todo . withID ( this ._id, this ._title, this ._priority, this ._date, [ this ._descrition]); } Getter int get id => _id; String get title => _title; Setter set title ( String newTitle) { if (newTitle.length <= 255 ) { _title = newTitle; } } set descrition ( String newDescrition) { if (newDescrition.length <= 255 ) { _descrition = newDescrition; } } Dynamic Map < String , dynamic > toMap () { var map = Map < String , dynamic > (); map[ "title" ] = _title; map[ "description" ] = _descrition; map[ "priority" ] = _priority; map[ "date" ] = _date; if (_id != nu...

Flutter - TextField / TextEditingController / RaisedButton

Flutter theme TextStyle textStyle = Theme . of (context).textTheme.title; Use on text field TextField ( decoration : InputDecoration ( labelText : "Distance" , hintText : 'e.g. 123' , labelStyle : textStyle, border : OutlineInputBorder ( borderRadius : BorderRadius . circular ( 5.0 ) ) ), keyboardType : TextInputType .number, onChanged : ( String string) { setState (() { name = string; }); }, ), TextEditing Controller class _FuelFormState extends State < FuelForm > { String name = "" ; final _currencies = [ 'Dollars' , 'Euro' , 'Pounds' ]; String _currency = 'Dollars' ; TextEditingController textEditingController = TextEditingController (); String result = "" ; @override Widget build ( BuildContext context) { TextStyle textStyle = Theme . of (context).textTheme.title; return Scaffold ( a...

Flutter - State (Text field, Dropdown)

State To create a text field import 'package:flutter/material.dart' ; void main () => runApp ( MyApp ()); class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build ( BuildContext context) { return MaterialApp ( title : 'Hello you' , theme : ThemeData ( primarySwatch : Colors .blue, ), home : new HelloYou (), ); } } class HelloYou extends StatefulWidget { @override State < StatefulWidget > createState () => new _HelloYouState (); } class _HelloYouState extends State < HelloYou > { String name = "" ; final _currencies = [ 'Dollars' , 'Euro' , 'Pounds' ]; String _currency = 'Dollars' ; @override Widget build ( BuildContext context) { return Scaffold ( appBar : AppBar ( title : Text ( "Hello" ), backgroundColor : Colors .blueAccent, ), body : Co...

Flutter

Run (launch.json) "program" : "lib/main8_ui_row_col.dart" , Padding padding : EdgeInsets . only (top : 30.0 , left : 20.0 ), Columns Column ( children : < Widget > []) Rows Row ( children : < Widget > []) Align elements Expanded () Font https://fonts.google.com fontFamily : 'Fredericka' , fontWeight : FontWeight .w700, pubspec.yaml fonts : - family : Fredericka fonts : - asset : fonts/FrederickatheGreat-Regular.ttf weight : 700 Image (not support SVG) http://clipart-library.com pubspec.yaml assets : - images/5TRrG7gLc.png class BowlImage extends StatelessWidget { @override Widget build ( BuildContext context) { AssetImage myImage = AssetImage ( 'images/5TRrG7gLc.png' ); Image image = Image (image : myImage, width : 400.0 , height : 400.0 ,); return Container (child : image,); } } Button class Orderbutton extends Statel...