vendredi 29 juillet 2022

Is there any way to choose a random document in firebase and flutter

I'm trying to make a positive phrases app, which will appear happy phrases like: "You are very important; Fight as you can, but never give up" and if you click on the "again" button (in Portuguese "again") another phrase will appear.

But I'm stuck on how I'm going to show these phrases within the space I've placed (a white rectangle in the center), and how to choose them randomly. I'm new to programming, sorry for any stupid questions.

My initial idea was to create a database in firebase where I would put the phrases and could update them periodically, and so I would also get them somehow randomly.

Photo of my project

Here is my code:

import 'package:flutter/material.dart';
import 'package:adobe_xd/pinned.dart';
import './home_mob.dart';
import 'package:adobe_xd/page_link.dart';
import './produtos_mob.dart';
import './about_us_mob.dart';
import 'package:flutter_svg/flutter_svg.dart';

class Virtual0 extends StatelessWidget {
  Virtual0({
    Key? key,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xff5808fb),
      body: Stack(
        children: <Widget>[
          Pinned.fromPins(
            Pin(start: 8.5, end: 9.5),
            Pin(size: 33.5, start: 39.0),
            child: Stack(
              children: <Widget>[
                Pinned.fromPins(
                  Pin(size: 37.0, start: 51.0),
                  Pin(size: 19.0, start: 0.0),
                  child: PageLink(
                    links: [
                      PageLinkInfo(
                        transition: LinkTransition.Fade,
                        ease: Curves.easeOut,
                        duration: 0.3,
                        pageBuilder: () => HomeMob(),
                      ),
                    ],
                    child: Text(
                      'Inicio',
                      style: TextStyle(
                        fontFamily: 'Bauhaus Modern',
                        fontSize: 16,
                        color: const Color(0xffffffff),
                      ),
                      softWrap: false,
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment(-0.027, -1.0),
                  child: SizedBox(
                    width: 65.0,
                    height: 19.0,
                    child: PageLink(
                      links: [
                        PageLinkInfo(
                          transition: LinkTransition.Fade,
                          ease: Curves.easeOut,
                          duration: 0.3,
                          pageBuilder: () => ProdutosMob(),
                        ),
                      ],
                      child: Text(
                        'Produtos',
                        style: TextStyle(
                          fontFamily: 'Bauhaus Modern',
                          fontSize: 16,
                          color: const Color(0xffffffff),
                        ),
                        softWrap: false,
                      ),
                    ),
                  ),
                ),
                Pinned.fromPins(
                  Pin(size: 46.0, end: 50.0),
                  Pin(size: 19.0, start: 0.0),
                  child: PageLink(
                    links: [
                      PageLinkInfo(
                        transition: LinkTransition.Fade,
                        ease: Curves.easeOut,
                        duration: 0.3,
                        pageBuilder: () => AboutUsMob(),
                      ),
                    ],
                    child: Text(
                      'Sobre',
                      style: TextStyle(
                        fontFamily: 'Bauhaus Modern',
                        fontSize: 16,
                        color: const Color(0xffffffff),
                      ),
                      softWrap: false,
                    ),
                  ),
                ),
                Pinned.fromPins(
                  Pin(start: 0.0, end: 0.0),
                  Pin(size: 1.0, end: 0.0),
                  child: SvgPicture.string(
                    _svg_oyi0he,
                    allowDrawingOutsideViewBox: true,
                    fit: BoxFit.fill,
                  ),
                ),
              ],
            ),
          ),
          Pinned.fromPins(
            Pin(start: 25.0, end: 25.0),
            Pin(size: 547.0, end: 107.0),
            child: Stack(
              children: <Widget>[
                Container(
                  decoration: BoxDecoration(
                    color: const Color(0xffffffff),
                    borderRadius: BorderRadius.circular(45.0),
                    border:
                        Border.all(width: 1.0, color: const Color(0xff707070)),
                  ),
                ),
                Pinned.fromPins(
                  Pin(start: 19.0, end: 19.0),
                  Pin(size: 59.0, start: 21.0),
                  child: Text(
                    'Frase do dia',
                    style: TextStyle(
                      fontFamily: 'Bauhaus Modern',
                      fontSize: 49,
                      color: const Color(0xff5808fb),
                    ),
                    softWrap: false,
                  ),
                ),
                Pinned.fromPins(
                  Pin(size: 190.0, middle: 0.5037),
                  Pin(size: 37.0, end: 32.0),
                  child: Stack(
                    children: <Widget>[
                      Container(
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            begin: Alignment(0.0, -1.0),
                            end: Alignment(0.0, 1.0),
                            colors: [
                              const Color(0xff5808fb),
                              const Color(0xff9929ea)
                            ],
                            stops: [0.0, 1.0],
                          ),
                          borderRadius: BorderRadius.circular(150.0),
                        ),
                      ),
                      Pinned.fromPins(
                        Pin(size: 107.0, middle: 0.4337),
                        Pin(size: 24.0, start: 4.0),
                        child: Text(
                          'novamente',
                          style: TextStyle(
                            fontFamily: 'Bauhaus Modern',
                            fontSize: 20,
                            color: const Color(0xffffffff),
                          ),
                          softWrap: false,
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  decoration: BoxDecoration(
                    color: const Color(0xffffffff),
                    boxShadow: [
                      BoxShadow(
                        color: const Color(0x29000000),
                        offset: Offset(0, 3),
                        blurRadius: 6,
                      ),
                    ],
                  ),
                  margin: EdgeInsets.fromLTRB(33.0, 105.0, 44.0, 105.0),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

const String _svg_oyi0he =
    '<svg viewBox="8.5 71.5 357.0 1.0" ><path transform="translate(8.5, 71.5)" d="M 0 1 L 357 0" fill="none" stroke="#ffffff" stroke-width="2" stroke-miterlimit="4" stroke-linecap="round" /></svg>';



Aucun commentaire:

Enregistrer un commentaire