From 63f2b183992b41e4de145a28a61252834a3bfd71 Mon Sep 17 00:00:00 2001 From: wjrcode Date: Thu, 13 Oct 2022 21:53:40 -0300 Subject: [PATCH] Listas --- lib/Controller/ListaController.dart | 2 +- lib/Repository/ListaRepository.dart | 10 +- .../navigation/bottom_navigation_bar.dart | 70 +++++++- lib/listas_page.dart | 163 ++++++++++++++++++ 4 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 lib/listas_page.dart diff --git a/lib/Controller/ListaController.dart b/lib/Controller/ListaController.dart index 86e9a3e..2bad72b 100644 --- a/lib/Controller/ListaController.dart +++ b/lib/Controller/ListaController.dart @@ -102,7 +102,7 @@ class ListaController extends Base { } } - Future?> getListas() async { + Future> getListas() async { return await repository.getListas(); } diff --git a/lib/Repository/ListaRepository.dart b/lib/Repository/ListaRepository.dart index 30e7d7b..0b382fc 100644 --- a/lib/Repository/ListaRepository.dart +++ b/lib/Repository/ListaRepository.dart @@ -37,17 +37,17 @@ class ListaRepository { return ResponseAPIModel.fromJson(jsonDecode(response.body)); } - Future> getListas() async { + Future> getListas() async { Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/listas'); var _url = Uri.parse(_uriSearchProduto.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); - List listaProdutos = (jsonMap['listas'] as List) - .map((item) => ListaModel.fromJson(item)) - .toList(); + // List listaProdutos = (jsonMap['listas'] as List) + // .map((item) => ListaModel.fromJson(item)) + // .toList(); - return listaProdutos; + return jsonMap; } } diff --git a/lib/components/navigation/bottom_navigation_bar.dart b/lib/components/navigation/bottom_navigation_bar.dart index 0f88124..04ad9e6 100644 --- a/lib/components/navigation/bottom_navigation_bar.dart +++ b/lib/components/navigation/bottom_navigation_bar.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:organizei/components/navigation/menu.dart'; +import 'package:organizei/home_page.dart'; +import 'package:organizei/listas_page.dart'; import '../box.dart'; @@ -16,6 +18,7 @@ class ButtonNavigatorBar extends StatefulWidget { class _ButtonNavigatorBarState extends State with SingleTickerProviderStateMixin { bool addIcone = false; + String iconSelected = 'home'; Offset offset = const Offset(0, 2); @@ -65,12 +68,35 @@ class _ButtonNavigatorBarState extends State mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( - icon: Icon(Icons.home_outlined), - onPressed: () {}, + icon: Icon( + Icons.home_outlined, + color: iconSelected == 'home' + ? const Color(0xFFF7BC36) + : Colors.black, + ), + onPressed: () { + setState(() { + iconSelected = 'home'; + }); + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => HomePage(), + ), + ); + }, ), IconButton( - icon: Icon(Icons.bar_chart_outlined), - onPressed: () {}, + icon: Icon( + Icons.bar_chart_outlined, + color: iconSelected == 'dashboard' + ? const Color(0xFFF7BC36) + : Colors.black, + ), + onPressed: () { + setState(() { + iconSelected = 'dashboard'; + }); + }, ), Container( child: IconButton( @@ -99,12 +125,40 @@ class _ButtonNavigatorBarState extends State ), ), IconButton( - icon: Icon(Icons.list_outlined), - onPressed: () {}, + icon: Icon( + Icons.list_outlined, + color: iconSelected == 'listas' + ? const Color(0xFFF7BC36) + : Colors.black, + ), + onPressed: () { + setState(() { + iconSelected = 'listas'; + }); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const ListasPage()), + ); + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (BuildContext context) => ListasPage(), + // ), + // ); + }, ), IconButton( - icon: Icon(Icons.folder_outlined), - onPressed: () {}, + icon: Icon( + Icons.folder_outlined, + color: iconSelected == 'projetos' + ? const Color(0xFFF7BC36) + : Colors.black, + ), + onPressed: () { + setState(() { + iconSelected = 'projetos'; + }); + }, ), ], ), diff --git a/lib/listas_page.dart b/lib/listas_page.dart new file mode 100644 index 0000000..208a61e --- /dev/null +++ b/lib/listas_page.dart @@ -0,0 +1,163 @@ +import 'package:flutter/material.dart'; +import 'package:http/retry.dart'; +import 'package:intl/date_symbol_data_local.dart'; +import 'package:organizei/Controller/ListaController.dart'; +import 'package:organizei/Controller/TarefaController.dart'; +import 'package:organizei/Model/Habito/HabitoModel.dart'; +import 'package:organizei/Model/Lista/ListaModel.dart'; +import 'package:organizei/Model/Tarefa/TarefaModel.dart'; +import 'package:organizei/Repository/ListaRepository.dart'; +import 'package:organizei/Repository/TarefaRepository.dart'; +import 'package:organizei/components/card_item.dart'; +import 'package:intl/intl.dart'; +import 'package:organizei/components/dialogs/habitos/habitoDialog.dart'; +import 'package:organizei/components/dialogs/tarefas/tarefaDialog.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import 'components/box.dart'; +import 'components/navigation/bottom_navigation_bar.dart'; +import 'components/texto_contornado.dart'; + +String getSaudacao() { + int horaAtual = new DateTime.now().hour; + + if (horaAtual > 4 && horaAtual < 13) { + return 'Bom dia,'; + } else if (horaAtual > 12 && horaAtual < 19) { + return 'Boa tarde,'; + } else { + return 'Boa Noite,'; + } +} + +String getDia() { + DateTime data = new DateTime.now(); + + Intl.defaultLocale = 'pt_BR'; + initializeDateFormatting('pt_BR'); + + return DateFormat.MMMMd().format(data); +} + +class ListasPage extends StatefulWidget { + const ListasPage({Key? key}) : super(key: key); + + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State { + late String? apelido = ''; + + @override + initState() { + getApelido(); + super.initState(); + } + + getApelido() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + + setState(() { + apelido = prefs.getString('UsuarioApelido'); + }); + } + + @override + Widget build(BuildContext context) { + late ListaController listaController; + listaController = ListaController(ListaRepository(), context); + + return Scaffold( + resizeToAvoidBottomInset: false, + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + extendBody: true, + backgroundColor: const Color(0xFFE9E9E9), + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(24.0, 80.0, 24.0, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextoContornado( + texto: 'Listas', + tamanho: 32, + cor: const Color(0xFF6385C3), + ) + ], + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 0.0), + child: Column(children: [ + FutureBuilder( + future: listaController.getListas(), + builder: (context, AsyncSnapshot snapshot) { + if (!snapshot.hasData) { + return const Center( + child: CircularProgressIndicator()); + } + + if (snapshot.hasError) { + return const Center( + child: Text('Ocorreu um erro!'), + ); + } + + if (snapshot.data.length == 0) { + return const Center( + child: + Text("Você não tem nada pra fazer hoje!"), + ); + } + + return ListView.builder( + primary: false, + shrinkWrap: true, + itemCount: snapshot.data['listas'].length, + itemBuilder: (context, index) { + var item = ListaModel.fromJson( + snapshot.data['listas'][index]); + + //var dialog; + + return cardItem( + cor: Color(int.tryParse( + item.cor ?? '0xFF6385C3') ?? + 0), + nome: item.nome, + horario: '', + abrirDialog: () {}); + }); + }), + ]), + ) + ], + ), + ], + ), + ), + ), + floatingActionButton: ButtonNavigatorBar( + fecharDialog: () { + setState(() {}); + }, + ) + // + ); + } +}