0% found this document useful (0 votes)
19 views3 pages

CodigoTiagoQuarta20 09

The document describes a Flutter app that: 1) Displays a welcome message when a name is entered in a text field and a button is pressed, saving the message to the screen. 2) Uses shared preferences to save a counter value that is incremented when a floating action button is tapped, displaying the updated count. 3) Loads the initial counter value from shared preferences on app start.

Uploaded by

famarques17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

CodigoTiagoQuarta20 09

The document describes a Flutter app that: 1) Displays a welcome message when a name is entered in a text field and a button is pressed, saving the message to the screen. 2) Uses shared preferences to save a counter value that is incremented when a floating action button is tapped, displaying the updated count. 3) Loads the initial counter value from shared preferences on app start.

Uploaded by

famarques17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import "package:flutter/material.

dart";

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context){
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Boas Vindas")
),
body: Column(
children: [
Text("Digite Seu Nome:"),
BoasVindas()

]
)
)
);
}
}

class BoasVindas extends StatefulWidget {


@override

BoasVindasState createState() => new BoasVindasState();


}

class BoasVindasState extends State<BoasVindas> {

final controladorNome = TextEditingController();


String frase = "";
@override
Widget build(BuildContext context){
return Container(
child: Column(
children: [
TextField(controller: controladorNome),
SizedBox(height: 30),
ElevatedButton(
child: Text('Enviar'),
onPressed: () {
setState((){
frase = "Bem Vindo, " + controladorNome.text;
});
},
),
SizedBox(height: 30),
Text("$frase")

]
)
);
}
}
25/10/2023 - https://flutlab.io/editor/8131609e-b2f4-49ae-a057-0e1f98d551af
-----------

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(home: MyHomePage());
}
}

class MyHomePage extends StatefulWidget {


MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {


int contador = 0;

@override
void initState() {
carregaContador();
}

void carregaContador() async {


// Conexão com o banco de dados chave-valor
final banco = await SharedPreferences.getInstance();
setState(() {
contador = (banco.getInt('contador') ?? 0);
});
}

void incrementa() async {


final banco = await SharedPreferences.getInstance();
setState(() {
contador = (banco.getInt('contador') ?? 0) + 1;
banco.setInt('contador', contador);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Banco Chave-Valor')),
body: Center(
child: Column(
children: [Text('Número de Touches'), Text('$contador')],
)),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
tooltip: 'Incremento',
onPressed: incrementa,
),
);
}
}

https://flutlab.io/editor/6d92c751-0476-40ae-9d0e-1fc7a591d024

You might also like