Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'package:app_esdudez/models/ciclo_model.dart';
- import 'package:flutter/material.dart';
- import 'package:scoped_model/scoped_model.dart';
- import 'home_estudarFinal.dart';
- import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
- import 'package:intl/intl.dart';
- import 'package:app_esdudez/widgets/bordaContainer.dart';
- class HomeEstudar extends StatefulWidget {
- @override
- _HomeEstudar createState() => _HomeEstudar();
- }
- class _HomeEstudar extends State<HomeEstudar>
- with SingleTickerProviderStateMixin {
- @override
- void initState() {
- super.initState();
- _animationController =
- AnimationController(vsync: this, duration: Duration(milliseconds: 300));
- DateTime now = DateTime.now();
- _date = DateFormat('dd-MM-yyyy').format(now);
- }
- @override
- void dispose() {
- super.dispose();
- _animationController.dispose();
- }
- List<String> materia = [
- // lista de materias
- "Ingles",
- "Portugues",
- "Matematica",
- "Direito Processual Penal"
- ];
- final _scaffoldKey = GlobalKey<ScaffoldState>();
- final _assuntoController = TextEditingController();
- final _formKey = GlobalKey<FormState>();
- AnimationController _animationController;
- Stopwatch watch = new Stopwatch();
- Timer timer;
- String _date = "Data"; // Dia do estudo
- String _time = "Tempo";
- String elapsedTime = '00:00:00'; // tempo de estudo
- String tempoManual;
- String dropdownValue = 'Ingles'; //materia escolhida
- String newValue;
- String textoMenu = "Selecione a matéria";
- String assunto = ''; // assunto que está estudando
- String textoBotaoPlay = "Iniciar";
- String hoursStr = "00";
- String minutesStr = "00";
- String secondsStr = "00";
- bool assuntoControle = true;
- bool tempoIniciado = false;
- bool isPlaying = false;
- bool _isButtonLembreteDisabled = false;
- bool _isButtonTempoManualDisabled = false;
- bool _isButtonDataDisabled = false;
- int dropdownbuttonControle = 2;
- int buttonControle = 2;
- int timeSoFar;
- int timeSoFarHoras;
- int timeSoFarMinutos;
- int timeSoFarSegundos;
- int valorWidget = 0;
- int valorPadrao = 0;
- double cardControle = 3;
- var _height = 300.0;
- var _heightPadrao = 90.0;
- var _widthPadrao = 90.0;
- @override
- Widget build(BuildContext context) {
- // usar model,
- // criar variavel no ciclo by user, para a materia do ciclo
- // cirar uma funçao no model, par varrer as materias e pegar a primeira que nao foi estudada
- // puxar a materia que nao foi estudada para essa tela, (função retorna materia)
- // usar materia, ou pegar id dela, para adicionar as os topicos, com o id dela..
- final List<Widget> myWidget = [
- teste(),
- teste2(),
- ];
- final List<Widget> myPadrao = [
- padrao(),
- padrao2(),
- ];
- print('Tela Estudar.');
- return ScopedModelDescendant<CicloModel>(builder: (context, child, model) {
- model
- .getMateriaParaEstudo(); // chama função para buscar proxima materia para estudar...
- if (model.isLoading) {
- print("entrou no if model loading..");
- // CHAMA FUNÇAO DEDICADA A ESSA TELA
- return Center(
- child: CircularProgressIndicator(
- valueColor: new AlwaysStoppedAnimation<Color>(Colors.white)),
- );
- } else {
- print("entrou no ELSE");
- print(model.materiaParaEstudo.nome);
- print(model.materiaParaEstudo.index);
- return Scaffold(
- backgroundColor: Colors.white,
- resizeToAvoidBottomPadding: false,
- key: _scaffoldKey,
- body: Container(
- color: Colors.blue,
- child: Container(
- decoration: bordaContainer(), // Borda do body do Scafold
- child: SingleChildScrollView(
- child: Padding(
- padding: EdgeInsets.only(
- top: 5, left: 15, right: 15, bottom: 15),
- child: Column(
- children: <Widget>[
- AnimatedContainer(
- height: _height,
- duration: Duration(seconds: 1),
- child: myWidget[valorWidget],
- ),
- Padding(
- padding: EdgeInsets.only(bottom: 20),
- ),
- GestureDetector(
- child: Card(
- elevation: 8,
- color: Colors.blue,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(500)),
- child: AnimatedContainer(
- duration: Duration(seconds: 1),
- height: _heightPadrao,
- width: _widthPadrao,
- child: AnimatedSwitcher(
- duration: Duration(seconds: 5),
- child: myPadrao[valorPadrao],
- ),
- ),
- ),
- onTap: onpressedIniciar(),
- ),
- Text(
- "Iniciar",
- style: TextStyle(fontSize: 15),
- ),
- Container(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: <Widget>[
- botaoParar(), // Botao que para de contar o tempo
- SizedBox(width: 50.0),
- botaoReiniciar(),
- ],
- ))
- ],
- ),
- )))),
- floatingActionButton: FloatingActionButton.extended(
- ///BOTAO FINALIZAR
- heroTag: 'teste5',
- onPressed:
- onpressedAvancar(), // Ações realizadas quando o botao avançar é pressionado
- label: Text(
- "Avançar",
- style: TextStyle(fontSize: 15),
- ),
- backgroundColor: Colors.blue,
- ),
- floatingActionButtonLocation:
- FloatingActionButtonLocation.endFloat);
- }
- });
- }
- updateTime(Timer timer) {
- if (watch.isRunning) {
- setState(() {
- elapsedTime = transformMilliSeconds(watch.elapsedMilliseconds);
- });
- }
- }
- startWatch() {
- watch.start();
- timer = new Timer.periodic(new Duration(milliseconds: 100), updateTime);
- }
- stopWatch() {
- watch.stop();
- setTime();
- }
- resetWatch() {
- watch.reset();
- setTime();
- }
- setTime() {
- timeSoFar = watch.elapsedMilliseconds;
- setState(() {
- elapsedTime = transformMilliSeconds(timeSoFar);
- });
- }
- transformMilliSeconds(int milliseconds) {
- int hundreds = (milliseconds / 10).truncate();
- int seconds = (hundreds / 100).truncate();
- int minutes = (seconds / 60).truncate();
- int hours = (minutes / 60).truncate();
- setState(() {
- hoursStr = (hours % 60).toString().padLeft(2, '0');
- minutesStr = (minutes % 60).toString().padLeft(2, '0');
- secondsStr = (seconds % 60).toString().padLeft(2, '0');
- });
- return "$hoursStr:$minutesStr:$secondsStr";
- }
- void _handleOnPressed() {
- setState(() {
- isPlaying = !isPlaying;
- isPlaying
- ? _animationController.forward()
- : _animationController.reverse();
- });
- }
- Function onpressedLembrete() {
- if (_isButtonLembreteDisabled) {
- return null;
- } else {
- return () {
- // do anything else you may want to here
- };
- }
- }
- Function onpressedTempoManual() {
- if (_isButtonTempoManualDisabled) {
- return null;
- } else {
- return () {
- if (_formKey.currentState.validate()) {
- if (dropdownValue != null) {
- DatePicker.showTimePicker(context,
- theme: DatePickerTheme(
- containerHeight: 210.0,
- ),
- showTitleActions: true, onConfirm: (time) {
- print('confirm $time');
- _time = '${time.hour}:${time.minute}:${time.second}';
- setState(() {
- //startWatch();
- //stopWatch();
- });
- }, currentTime: DateTime.now(), locale: LocaleType.en);
- setState(() {});
- }
- } else {
- _scaffoldKey.currentState.showSnackBar(
- SnackBar(content: Text("Voce nao selecionou a materia")));
- }
- };
- }
- }
- Function onpressedData() {
- if (_isButtonDataDisabled) {
- return null;
- } else {
- return () {
- DatePicker.showDatePicker(context,
- theme: DatePickerTheme(
- containerHeight: 210.0,
- ),
- showTitleActions: true,
- minTime: DateTime(2000, 1, 1),
- maxTime: DateTime(2050, 12, 31), onConfirm: (date) {
- print('confirm $date');
- _date = '${date.day}-${date.month}-${date.year}';
- setState(() {});
- }, currentTime: DateTime.now(), locale: LocaleType.en);
- };
- }
- }
- Function onpressedIniciar() {
- return () {
- if (_formKey.currentState.validate()) {
- if (dropdownValue != null) {
- if (tempoIniciado == false) {
- setState(() {
- _heightPadrao = 230.0;
- _widthPadrao = 230.0;
- _height = 140.0;
- valorWidget = 1;
- valorPadrao = 1;
- assuntoControle = false;
- _isButtonLembreteDisabled = true;
- _isButtonTempoManualDisabled = true;
- _isButtonDataDisabled = true;
- textoMenu = dropdownValue;
- dropdownbuttonControle = 0;
- cardControle = 1;
- tempoIniciado = true;
- textoBotaoPlay = "Pausar";
- });
- startWatch();
- _handleOnPressed();
- } else {
- setState(() {
- textoBotaoPlay = "Iniciar";
- tempoIniciado = false;
- });
- _handleOnPressed();
- stopWatch();
- }
- } else {
- Scaffold.of(context).showSnackBar(
- SnackBar(content: Text("Voce nao selecionou a materia")));
- }
- }
- };
- }
- Function onpressedParar() {
- return () {
- if (tempoIniciado != false) {
- setState(() {
- textoBotaoPlay = "Iniciar";
- tempoIniciado = false;
- });
- _handleOnPressed();
- stopWatch();
- }
- };
- }
- Function onpressedReiniciar() {
- return () {
- showDialog<String>(
- context: context,
- barrierDismissible:
- true, // dialog is dismissible with a tap on the barrier
- builder: (BuildContext context) {
- return AlertDialog(
- // CONCLUIR.....
- title: Text(
- 'Tem certeza que quer reiniciar o tempo?',
- style: TextStyle(fontSize: 15),
- ),
- actions: <Widget>[
- FlatButton(
- child: Text(
- 'Não',
- style: TextStyle(fontSize: 15),
- ),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- FlatButton(
- child: Text(
- 'Sim',
- style: TextStyle(fontSize: 15),
- ),
- onPressed: () {
- resetWatch();
- if (tempoIniciado == true) {
- stopWatch();
- setState(() {
- textoBotaoPlay = "Iniciar";
- tempoIniciado = false;
- });
- _handleOnPressed();
- }
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- },
- );
- };
- }
- Widget espaco() {
- return Padding(
- padding: EdgeInsets.only(bottom: 10),
- );
- }
- Function onpressedAvancar() {
- return () {
- //if (_formKey.currentState.validate()) {
- if (dropdownValue != null) {
- if (cardControle == 1) {
- if (tempoIniciado == true) {
- stopWatch();
- setState(() {
- textoBotaoPlay = "Iniciar";
- tempoIniciado = false;
- });
- _handleOnPressed();
- }
- Navigator.of(context).push(
- MaterialPageRoute(builder: (context) => HomeEstudarFinal()));
- } else {
- _scaffoldKey.currentState.showSnackBar(
- SnackBar(content: Text("Voce nao iniciou seu tempo")));
- }
- } else {
- _scaffoldKey.currentState.showSnackBar(
- SnackBar(content: Text("Voce nao selecionou a materia")));
- }
- //}
- };
- }
- Widget selecionaMateria() {
- return Container(
- decoration: BoxDecoration(
- border: Border.all(width: 0.1),
- color: Colors.white,
- ),
- child: DropdownButtonHideUnderline(
- child: ButtonTheme(
- alignedDropdown: true,
- child: DropdownButton<String>(
- isExpanded: true,
- hint: new Text(
- textoMenu,
- style: TextStyle(color: Colors.black, fontSize: 15.0),
- ),
- value: dropdownValue,
- onChanged: dropdownbuttonControle > 1
- ? (newValue) {
- setState(() {
- dropdownValue = newValue;
- });
- }
- : null,
- items: materia.map<DropdownMenuItem<String>>((String value) {
- return DropdownMenuItem<String>(
- value: value,
- child: Text(
- value,
- style: TextStyle(color: Colors.black, fontSize: 15.0),
- ),
- );
- }).toList(),
- ),
- )),
- );
- }
- Widget digitaAssunto() {
- return Form(
- key: _formKey,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- "Digite o assunto que está estudando",
- style: TextStyle(fontSize: 15),
- ),
- TextFormField(
- controller: _assuntoController,
- maxLength: 70,
- enabled: assuntoControle,
- key: Key('Assunto'),
- style: TextStyle(color: Colors.black, fontSize: 15.0),
- validator: (value) {
- // verificar alerta de erro
- if (value.isEmpty) {
- return 'Por favor digite o assunto';
- } else {
- setState(() {
- assunto = value;
- });
- }
- },
- onSaved: (value) {
- setState(() {
- assunto = value;
- });
- },
- ),
- ],
- ),
- );
- }
- Widget diaEstudo() {
- return GestureDetector(
- onTap: onpressedData(),
- child: Container(
- alignment: Alignment.center,
- //height: 50.0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Row(
- children: <Widget>[
- Container(
- child: Row(
- children: <Widget>[
- Icon(
- Icons.date_range,
- size: 15.0,
- color: Colors.black,
- ),
- Text(
- " Dia: $_date",
- style: TextStyle(color: Colors.black, fontSize: 15.0),
- ),
- ],
- ),
- )
- ],
- ),
- Text(
- " Trocar",
- style: TextStyle(color: Colors.black, fontSize: 15.0),
- ),
- ],
- ),
- ),
- );
- }
- Widget botaoParar() {
- return Column(
- //BOTAO PARAR
- children: <Widget>[
- SizedBox(
- width: 40,
- height: 40,
- child: new FloatingActionButton(
- heroTag: 'teste1',
- elevation: 5,
- backgroundColor: Colors.white,
- onPressed: onpressedParar(),
- child: new Icon(
- Icons.stop,
- color: Colors.black,
- size: 20,
- )),
- ),
- Padding(
- padding: EdgeInsets.only(bottom: 3),
- ),
- Text(
- "Parar",
- style: TextStyle(fontSize: 12, color: Colors.black),
- ),
- ],
- );
- }
- Widget botaoIniciar() {
- return Column(
- //BOTAO INICIAR
- children: <Widget>[
- SizedBox(
- height: 60,
- width: 60,
- child: FloatingActionButton(
- heroTag: 'teste2',
- elevation: 5,
- backgroundColor: Colors.white,
- child: AnimatedIcon(
- icon: AnimatedIcons.play_pause,
- progress: _animationController,
- size: 35,
- color: Colors.black,
- ),
- onPressed: onpressedIniciar(),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(bottom: 3),
- ),
- Text(
- textoBotaoPlay,
- style: TextStyle(fontSize: 14, color: Colors.black),
- ),
- ],
- );
- }
- Widget botaoReiniciar() {
- return Column(
- //BOTAO REINICIAR
- children: <Widget>[
- SizedBox(
- width: 40,
- height: 40,
- child: new FloatingActionButton(
- heroTag: 'teste3',
- elevation: 5,
- backgroundColor: Colors.white,
- onPressed: onpressedReiniciar(),
- child: new Icon(
- Icons.refresh,
- color: Colors.black,
- size: 20,
- )),
- ),
- Padding(
- padding: EdgeInsets.only(bottom: 3),
- ),
- Text(
- "Reiniciar",
- style: TextStyle(fontSize: 12, color: Colors.black),
- ),
- ],
- );
- }
- Widget botaoLembrete() {
- return RaisedButton(
- color: Colors.white,
- child: Text("Definir Lembrete",
- style: TextStyle(fontSize: 15, color: Colors.black87)),
- onPressed: onpressedLembrete(),
- );
- }
- Widget botaoTempoManual() {
- return RaisedButton(
- color: Colors.white,
- child: Text("Tempo Manual",
- style: TextStyle(fontSize: 15, color: Colors.black87)),
- onPressed: onpressedTempoManual());
- }
- Widget teste() {
- return Card(
- elevation: cardControle,
- child: Padding(
- padding: EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
- child: Column(
- // coluna dentro do card
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- "Selecione a materia que irá estudar",
- style: TextStyle(fontSize: 15),
- ),
- espaco(), // Espaço entre os componentes
- selecionaMateria(), // Dropbutton, para selecionar a materia que ira estudar
- espaco(), // Espaço entre os componentes
- digitaAssunto(), // Espaço para digitar o assunto que sera estudado
- espaco(), // Espaço entre os componentes
- diaEstudo(), // Dia de estudo - por padrao é o dia atual, é possivel alterar
- espaco(), // Espaço entre os componentes
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- botaoLembrete(), // Defini um alarme para o tempo de estudo
- botaoTempoManual(), // Inseri um tempo manual, é possivel continuar a partir desse tempo
- // ainde precisa de ajustes
- ],
- )
- ],
- )));
- }
- Widget teste2() {
- return Card(
- elevation: 5,
- child: Padding(
- padding: EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
- child: Row(
- children: <Widget>[
- Column(
- // coluna dentro do card
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- "Direito Penal:",
- style: TextStyle(fontSize: 15),
- ),
- espaco(), // Espaço entre os componentes
- Text(
- "Principios Direito Penal",
- style: TextStyle(fontSize: 15),
- ),
- espaco(), // Espaço entre os componentes
- Row(
- children: <Widget>[
- Icon(
- Icons.date_range,
- size: 15.0,
- color: Colors.black,
- ),
- Padding(
- padding: EdgeInsets.only(left: 5),
- ),
- Text(
- "Dia: 10/12/2019",
- style: TextStyle(fontSize: 15),
- ),
- ],
- ),
- espaco(), // Espaço entre os componentes
- Row(
- children: <Widget>[
- Icon(
- Icons.access_alarm,
- size: 15.0,
- color: Colors.black,
- ),
- Padding(
- padding: EdgeInsets.only(left: 5),
- ),
- Text(
- "Alarme",
- style: TextStyle(fontSize: 15),
- ),
- ],
- ),
- ],
- )
- ],
- )));
- }
- Widget padrao() {
- return Padding(
- padding: EdgeInsets.all(3),
- child: Card(
- elevation: 5,
- color: Colors.white,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(500)),
- child: Container(
- alignment: AlignmentDirectional.center,
- child: AnimatedIcon(
- icon: AnimatedIcons.play_pause,
- progress: _animationController,
- size: 35,
- color: Colors.black,
- ),
- ),
- ),
- );
- }
- Widget padrao2() {
- return Padding(
- padding: EdgeInsets.all(3),
- child: Card(
- elevation: 5,
- color: Colors.white,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(500)),
- child: Container(
- alignment: AlignmentDirectional.center,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(top: 70),
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- hoursStr,
- style: TextStyle(fontSize: 45),
- ),
- Text(
- "h",
- style: TextStyle(fontSize: 15),
- ),
- Text(
- minutesStr,
- style: TextStyle(
- fontSize: 45,
- ),
- ),
- Text(
- "m",
- style: TextStyle(fontSize: 15),
- ),
- Text(
- secondsStr,
- style: TextStyle(fontSize: 45),
- ),
- Text(
- "s",
- style: TextStyle(fontSize: 15),
- ),
- ],
- ),
- Spacer(),
- AnimatedIcon(
- icon: AnimatedIcons.play_pause,
- progress: _animationController,
- size: 35,
- color: Colors.black,
- ),
- Padding(
- padding: EdgeInsets.only(bottom: 10),
- )
- ],
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement