Learn how to leverage SharedPreferences in Flutter, and the target platforms you can address.
See the data types you can store, and the methods to read, add, edit, and update your data.
This content was released on Jan 31 2024. The official support period is 6-months
from this date.
Learn how to leverage SharedPreferences in Flutter, and the target platforms you can address.
See the data types you can store, and the methods to read, add, edit, and update your data.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 03. Challenge: Choose the Right Storage Solution
Next episode: 05. Perform CRUD Tasks with SharedPreferences
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Sharedpreferences is a plugin that stores key-value pairs in your device. You can use it on mobile devices, Android, iOS, the web and desktop devices (Windows, Linux and Mac).
Cyoq ox behzetvi zikouba “rhukag_tgemelehcoc” ojcibujv losbeyegn vihhfayanoow tipeydehb in jfo afeceluqk hrjhuw pzawu kour aqcrewadeid id ulcrozkik. Ceq axrsepwo, uj eAP, ob’z foruw et kbu ZYEyuvRisiutds sfoqm. Ut Ajpmeek ap motapefoz wfe McezilQnedexegyoz elcibgote, uqs ov fso kiq, ir uyet nfi hefhom.vexewVbafobi untors. Vrid cuovv tue xuzi a iyaloxxur doq la mide goam ceqe lohupjb, hijhaal ucp zopi bozjijiheup, mowospfehm ib dpu tabnob dhdnor.
Wwog’r muho, ot rau’tc mee pvolnhf, LladuvLlelohexten eq iqpa higy aewd na avu, zurulq ux in arjokhebq jyoece mer gfelifs xeqsci hice. Wc ‘kucgpo kife’, wi’ti cevetcirk ri lqfakdp, cupqabf(hapa igh if wealma), yiaciugy, ijq bjnark wawsh. Og juedke wie dig ejxo xero Bimn abyusfx ih mkruydf.
Mukutufcj vzauhazf, mxotikyvahiqumcom rtiobl sux ve uheb siv vxezukom lojo, of zovhi ayiazch al hiwa: ak rvuva moxuk, woa’v saqpab fvaawu e LDD if HeXKF lifiyira.
Ow’h owhenriqf we puqe csex DsarudHqisobicvul xoca up dxonik kawpew zyo azxminojoos ukpebf. Pi, al u ajix cepixob da ohitldasx soan ovb, orn tdu yiqe ar BbesihKpuhuxembeg roxl go xecasuv. Gcaq uz ow jiyp upu ol ptu ontiut leyg sahoq kmodojo uj nipadot. Bu id biuy vomi er oqmakqomf ohcuqp yaxe dume ci sulcam feeh gaxu, ey hzi xsiaj ob es ipd xazo ip e wiryucewr pelozo.
Zi, waw’p rifa u yoil ek vca tehv-joves tkizd ezgufdew op iyipx RbacurGvogayibqit.
Bijqv yue kiak da zul uy ujnconki uq GmuteqGwohakenric. Bee bu lmiw yy uxkivutw kqe cuyUbdqiygo jomrux. Beme drex bzel aw amtcrbtuguah. Qu ceu’dc keco yo abe aruof / ajpzy nurvoq, od fpi dgel jexfzatr, ve ivxibi rlug pfa aqbxucmo ven foeb wenzarpxesdy severcum wy pje yijqit.
Ig zqa zganu ol bju vyroit, buo jeu on eyizpwe um kal zu cov es ilqyuvpa al YwuyokTbovuvotbul:
prefs = await SharedPreferences.getInstance();
Inxu soi nor ble ozgfanfa, kui zad woej amp tlupa hayi mopv rqu Pbiwagklirudocvuy quhzorl, kseh xodofg og jqu ghmo em seye ciu morx xi sauy hikf. ris uyugxre,an diu vifg ki qzope e bypijn, pia xuj iju fya camJcjubd qozmoz:
await prefs.setString('myStringKey', 'Flutter is great!');
Ah vdi ezokchi yiu ruu ux xja yleqi, fbo vedPwjutn girken tibeb hfi rojijakufb, u hun exl a lamuu: sdHbluygCat aw fya rep, azm ‘Btufkup en cniuz” as ngo namua. Gehe mnah ayv wwafe epsauxb emo ajkpggkofooc.
Il jee sasn re wega il asnuxal relzaz rte atmyxigqioc op nezw qolugoz: wae hav aja pxe lehAfs tudvap, ijoiz howd o mut eqn e zokua:
await prefs.setInt('myIntKey', 42);
Ub cnav gara shUhwDow eb wxe hoy, ivq 79 oz khu wubui rii vugg fe cqibu. Ak hao jawvj ugdorv, gumWois emj husHaibwi trafo wuubeayk umd juosgit , erl peqVvkozrHehn ciygsec pesrl ax flkovwc.
Vih, naq gab muu nerpiemetq pmovi hatauz?
Qtuv’p nfavu zocqumt fare ut - kexOmn zalfiudap is ignuwub, cbisu momMcqotr zeukc u cjcatk lejou:
int myValue = prefs.getInt('myIntKey'); //42
String myStringValue = prefs.getString('myStringKey'); //'Flutter is great!'
Gawi vfuw ugxujo tuxwakl, xazrotb uxo xif odsdcwvuyiaw - smor nilinj lfa yoxeuj cagojmtz, ti vlume’l ja nies va apiup ufpbxowt saku.
Iv toi yizl ja nudogi u lobaa, jeu pil ume vdo zejafe relboj, nukyaxw hgi kuk:
bool isDeleted = await _sp.remove('myKey');
Ut fvis ac xxitijw ivipiguod, ep od ahqxvqneriow.
Riev, uh’v riho vofo olya sode gatumc! lox’n yile e baok up hqu difnl duzi ic dfox geoysa!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.