Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:app_esdudez/controller/appTema.dart';
- import 'package:app_esdudez/controller/sizeConfig.dart';
- import 'package:app_esdudez/controller/stringsStatics.dart';
- import 'package:app_esdudez/models/infoMaterias_data.dart';
- import 'package:app_esdudez/widgets/customDialogAdd.dart';
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:flutter/material.dart';
- import 'dart:math';
- import 'dart:convert';
- import 'package:random_color/random_color.dart';
- import 'escolhaordemcicloView.dart';
- import 'package:app_esdudez/widgets/bordaContainer.dart';
- class EscolhaMateriaTab extends StatefulWidget {
- EscolhaMateriaTab({this.idMateriasArea});
- final List<dynamic> idMateriasArea;
- @override
- _EscolhaMateriaTab createState() => _EscolhaMateriaTab();
- }
- class _EscolhaMateriaTab extends State<EscolhaMateriaTab> {
- List<InfoMateriasData> listaMateriasArea = List<InfoMateriasData>();
- Map<String, bool> values = Map();
- final _scaffoldKey = GlobalKey<ScaffoldState>();
- int controle = 1;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- key: _scaffoldKey,
- backgroundColor: AppTema.appColor,
- appBar: AppBar(
- elevation: 0,
- title: Text(
- Strings.titleEscolhaMateria,
- style: Theme.of(context).textTheme.title
- ),
- centerTitle: true,
- actions: <Widget>[
- botaoAddNovaMateria(),
- ],
- ),
- resizeToAvoidBottomPadding: false,
- body: Container(
- color: AppTema.appColor,
- child: Container(
- decoration: bordaContainer(),
- child: FutureBuilder<QuerySnapshot>(
- future: Firestore.instance
- .collection("materia")
- .getDocuments(),
- builder: (context, snapshot) {
- if (!snapshot.hasData)
- return Center(
- child: CircularProgressIndicator(),
- );
- else {
- if (controle == 1) {
- listaMateriasArea.clear(); // limpar lista quando clicar na tela
- for (DocumentSnapshot doc in snapshot.data.documents) {
- InfoMateriasData data = InfoMateriasData.fromDocument(doc);
- for (int i = 0; i < widget.idMateriasArea.length; i++) {
- if (data.id.contains(widget.idMateriasArea[i])) {
- listaMateriasArea.add(data);
- values.putIfAbsent(
- data.nome, () => true); // Preenche o mapa
- }
- }
- }
- }
- return Container(
- margin: EdgeInsets.only(
- top: 0.7 * SizeConfig.heightMultiplier,
- left: 3.2 * SizeConfig.widthMultiplier,
- right: 3.2 * SizeConfig.widthMultiplier,
- ),
- child: listaMaterias(), //Lista de materias
- );
- }
- },
- ),
- )
- ),
- floatingActionButton: FloatingActionButton.extended(
- heroTag: 'tagAvancarMateria',
- label: Text(
- Strings.botaoAvancarMateria,
- style: Theme.of(context).textTheme.button
- ),
- backgroundColor: AppTema.appColor,
- onPressed:
- onpressedAvancar(),
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.endFloat
- );
- }
- String gerenateId(){
- var random = Random.secure();
- var valuesRandom = List<int>.generate(
- 15,
- (i) => random.nextInt(256)
- );
- var result = base64.encode(valuesRandom).toString();
- result = result.replaceAll('+', '9');
- result = result.replaceAll('/', '0');
- result = result.replaceAll("\\", '1');
- return result;
- }
- Widget botaoAddNovaMateria() {
- return IconButton(
- icon: Icon(
- Icons.add_box,
- ),
- onPressed: () {
- janelaAddNovaMateria2(context);
- },
- );
- }
- Widget listaMaterias() {
- return ListView(
- padding: EdgeInsets.only(
- bottom: 70), // precisa ser fixo
- children: values.keys.map((String key) {
- return Container(
- padding: EdgeInsets.only(
- bottom: 0.14 * SizeConfig.heightMultiplier),
- child: Card(
- shape: BeveledRectangleBorder(
- borderRadius: BorderRadius.circular(
- 0.7 * SizeConfig.heightMultiplier)
- ),
- elevation: 4,
- child: CheckboxListTile(
- title: Text(
- key,
- style: Theme.of(context).textTheme.body1,
- ),
- value: values[key],
- onChanged: (bool value) {
- setState(() {
- values[key] = value;
- });
- },
- ),
- ),
- );
- }).toList(),
- );
- }
- Function onpressedAvancar() {
- return () {
- List<bool> listbool = values.values.toList();
- List<InfoMateriasData> listaMateriasCiclo = List<InfoMateriasData>();
- for (int i = 0; i < listbool.length; i++) {
- if (listbool[i] == true) {
- listaMateriasCiclo.add(
- listaMateriasArea[i]);
- }
- }
- if (listaMateriasCiclo.length > 0 && listaMateriasCiclo.length <= 30) {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) =>
- EscolhaOrdemCicloTab(
- listaMaterias: listaMateriasCiclo)));
- } else {
- if (listaMateriasCiclo.length == 0) {
- _scaffoldKey.currentState.showSnackBar(
- SnackBar(
- content: Text(
- Strings.onFailSelecionaMateria,
- style: Theme.of(context).textTheme.body1.copyWith(
- color: Colors.white)
- ),
- backgroundColor: AppTema.erroColor,
- duration: Duration(
- seconds: 2),
- )
- );
- } else {
- int qtdmaterias = listaMateriasCiclo.length;
- _scaffoldKey.currentState.showSnackBar(
- SnackBar(
- content: Text(
- "Voce selecionou " +
- '$qtdmaterias materias' +
- Strings.onFailNumeroMaxMateria,
- style: Theme.of(context).textTheme.body1.copyWith(
- color: Colors.white)
- ),
- backgroundColor: AppTema.erroColor,
- duration: Duration(
- seconds: 5),
- )
- );
- }
- }
- };
- }
- Future<String> janelaAddNovaMateria2 (BuildContext context) async {
- String novaMateria = '';
- return showDialog<String>(
- context: context,
- barrierDismissible: true,
- builder: (BuildContext context) {
- return Dialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(
- 2.3 * SizeConfig.heightMultiplier),
- ),
- elevation: 0.0,
- backgroundColor: Colors.transparent,
- child: Stack(
- children: <Widget>[
- Container(
- padding: EdgeInsets.only(
- top: 11.6 * SizeConfig.widthMultiplier + 2.3 * SizeConfig.heightMultiplier,
- bottom: 2 * SizeConfig.heightMultiplier,
- left: 5 * SizeConfig.widthMultiplier,
- right: 5 * SizeConfig.widthMultiplier,
- ),
- margin: EdgeInsets.only(
- top: 11.6 * SizeConfig.widthMultiplier),
- decoration: BoxDecoration(
- color: Colors.white,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.circular(
- 2.3 * SizeConfig.heightMultiplier),
- boxShadow: [
- BoxShadow(
- color: Colors.black26,
- blurRadius: 10.0,
- offset: const Offset(0.0, 10.0),
- ),
- ],
- ),
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Align(
- alignment: Alignment.topCenter,
- child: Text(
- Strings.titleDialogAddMateria,
- style: Theme.of(context).textTheme.title.copyWith(
- color: AppTema.appColor)
- ),
- ),
- SizedBox(
- height: 2 * SizeConfig.heightMultiplier),
- Align(
- alignment: Alignment.center,
- child: TextField(
- style: Theme.of(context).textTheme.body1,
- maxLines: 1,
- maxLength: 70,
- autofocus: true,
- decoration: InputDecoration(
- labelText: 'Nome da materia',
- labelStyle: TextStyle(
- fontSize: 2.2 * SizeConfig.textMultiplier,),
- hintText: 'Lingua Francesa',
- hintStyle: TextStyle(
- fontSize: 2.2 * SizeConfig.textMultiplier,
- )
- ),
- onChanged: (value) {
- setState(() {
- novaMateria = value;
- });
- },
- )
- ),
- SizedBox(
- height: 2 * SizeConfig.heightMultiplier),
- Flexible(
- child: Align(
- alignment: Alignment.bottomCenter,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Flexible(
- child: RaisedButton(
- child: Text(
- "Cancelar",
- style: Theme.of(context).textTheme.button
- ),
- color: AppTema.appColor,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(
- 4.4 * SizeConfig.heightMultiplier)),
- onPressed: () {
- Navigator.of(context).pop();
- }
- )
- ),
- Flexible(
- child: RaisedButton(
- child: Text(
- "Adicionar",
- style: Theme.of(context).textTheme.button.copyWith(
- fontWeight: FontWeight.bold,)
- ),
- color: AppTema.appColor,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(
- 4.4 * SizeConfig.heightMultiplier)),
- onPressed: (){
- setState(() {
- controle = 0;
- if (novaMateria.isEmpty == false) {
- RandomColor _randomColor = RandomColor();
- Color _color = _randomColor.randomColor();
- InfoMateriasData nova = InfoMateriasData.novaMateria( // id, nome, cor, tempo, estudou, desempenho, quantidadeTopicos
- gerenateId(),
- '$novaMateria',
- _color
- .toString()
- .replaceAll('Color(0xff', '')
- .replaceAll(')', '')
- .toUpperCase(),
- '00:00:00',
- false,
- '0.00',
- '0'
- );
- listaMateriasArea.add(nova);
- values.putIfAbsent(
- nova.nome, () => true);
- Navigator.of(context).pop();
- }
- });
- },
- )
- ),
- ],
- ),
- )
- )
- ],
- ),
- )
- ),
- Positioned(
- left: 3.7 * SizeConfig.widthMultiplier,
- right: 3.7 * SizeConfig.widthMultiplier,
- child: CircleAvatar(
- backgroundColor: AppTema.appBackgroundColor,
- radius: 7.3 * SizeConfig.heightMultiplier,
- child: Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(
- Radius.circular(
- 7.3 * SizeConfig.heightMultiplier))),
- child: Icon(
- Icons.error,
- color: AppTema.appColor,
- size: 14 * SizeConfig.heightMultiplier,
- )
- ),
- ),
- ),
- ],
- ),
- );
- }
- );
- }
- Future<String> janelaAddNovaMateria(BuildContext context) async {
- String novaMateria2 = '';
- return showDialog<String>(
- context: context,
- barrierDismissible: true,
- builder: (BuildContext context) => CustomDialogAdd(
- title: Strings.titleDialogAddMateria,
- novaMateria: novaMateria2,
- onPressedAddMateria: (){
- setState(() {
- controle = 0;
- if (novaMateria2.isEmpty == false) {
- RandomColor _randomColor = RandomColor();
- Color _color = _randomColor.randomColor();
- InfoMateriasData nova = InfoMateriasData.novaMateria( // id, nome, cor, tempo, estudou, desempenho, quantidadeTopicos
- gerenateId(),
- '$novaMateria2',
- _color
- .toString()
- .replaceAll('Color(0xff', '')
- .replaceAll(')', '')
- .toUpperCase(),
- '00:00:00',
- false,
- '0.00',
- '0'
- );
- listaMateriasArea.add(nova);
- values.putIfAbsent(
- nova.nome, () => true);
- }
- });
- },
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement