Advertisement
littleoak

App para gerar frases

Jan 19th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.18 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:math';
  3.  
  4. void main() {
  5.   runApp(MaterialApp(
  6.     home: new Home(),
  7.     debugShowCheckedModeBanner: false,
  8.   ));
  9. }
  10.  
  11. class Home extends StatefulWidget {
  12.   @override
  13.   _HomeState createState() => _HomeState();
  14. }
  15.  
  16. class _HomeState extends State<Home> {
  17.  
  18.   var _frases = [
  19.     "Frase grandeeeeeeeeeeeeeeeeeeeeeeeeeeee 1",
  20.     "Frase grandeeeeeeeeeeeeeeeeeeeeeeeeeeee 2",
  21.     "Frase grandeeeeeeeeeeeeeeeeeeeeeeeeeeee 3",
  22.     "Frase grandeeeeeeeeeeeeeeeeeeeeeeeeeeee 4"
  23.   ];
  24.  
  25.   var _fraseGerada = "Clique abaixo para gerar uma frase!";
  26.  
  27.   void _gerarFrase() {
  28.     var numeroSorteado = Random().nextInt(_frases.length);
  29.  
  30.     setState(() {
  31.       _fraseGerada = _frases[ numeroSorteado ];
  32.     });
  33.   }
  34.  
  35.   @override
  36.   Widget build(BuildContext context) {
  37.     return new Scaffold(
  38.       appBar: AppBar(
  39.         title: new Text("Frases do dia"),
  40.         backgroundColor: Colors.green,
  41.       ),
  42.       body: new Center(
  43.         child: Container(
  44.           padding: EdgeInsets.all(16),
  45.           //width: double.infinity,
  46.           /*decoration: BoxDecoration(
  47.               border: new Border.all(width: 3, color: Colors.amber)
  48.           ),*/
  49.           child: Column(
  50.             mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  51.             crossAxisAlignment: CrossAxisAlignment.center,
  52.             children: <Widget>[
  53.               Image.asset("images/logo.png"),
  54.               new Text(
  55.                 _fraseGerada,
  56.                 textAlign: TextAlign.justify,
  57.                 style: TextStyle(
  58.                     fontSize: 25,
  59.                     fontStyle: FontStyle.italic,
  60.                     color: Colors.black
  61.                 ),
  62.               ),
  63.               new RaisedButton(
  64.                 child: new Text(
  65.                   "Nova Frase",
  66.                   style: new TextStyle(
  67.                       fontSize: 25,
  68.                       color: Colors.white,
  69.                       fontWeight: FontWeight.bold
  70.                   ),
  71.                 ),
  72.                 color: Colors.green,
  73.                 onPressed: _gerarFrase,
  74.               )
  75.             ],
  76.           ),
  77.         )
  78.       ),
  79.     );
  80.   }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement