Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:PhotoReport/blocs/categoria_bloc.dart';
- import 'package:PhotoReport/blocs/image_bloc.dart';
- import 'package:PhotoReport/helpers/categoria_helper.dart';
- import 'package:PhotoReport/helpers/obra_helper.dart';
- import 'package:PhotoReport/pages/add_relatorio.dart';
- import 'package:PhotoReport/pages/home_page.dart';
- import 'package:PhotoReport/pages/relatorios_page.dart';
- import 'package:PhotoReport/widgets/Drawer.dart';
- import 'package:PhotoReport/widgets/FabBottomAppBar.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
- import 'package:shimmer/shimmer.dart';
- import 'camera.dart';
- import 'galeria_page.dart';
- import 'lista_categorias.dart';
- class CategoriasPage extends StatefulWidget {
- final Obra obra;
- final PageController controller;
- CategoriasPage(this.controller, this.obra);
- @override
- _CategoriasPageState createState() => _CategoriasPageState();
- }
- class _CategoriasPageState extends State<CategoriasPage> {
- Obra _obra;
- PageController _pageCtrl;
- PageController _pageCtrlCategorias = new PageController();
- String title = "Obras";
- int bottomSelectedIndex = 0;
- CategoriaBloc _bloc;
- int currentIndex = 0;
- @override
- void initState() {
- super.initState();
- _pageCtrl = widget.controller;
- _obra = widget.obra;
- _bloc = CategoriaBloc(buildingId: _obra.id);
- _bloc.outState.listen((state) {
- switch (state) {
- case CategoriaState.FAIL:
- showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: Text("Erro"),
- content: Text("Ocorreu um erro ao obter as obras!"),
- ));
- break;
- case CategoriaState.SUCCESS:
- case CategoriaState.LOADING:
- _buildLoadingWidget();
- break;
- case CategoriaState.IDLE:
- }
- });
- }
- @override
- void dispose() {
- super.dispose();
- _bloc.dispose();
- }
- void bottomTapped(int index) {
- setState(() {
- currentIndex = index;
- switch (index) {
- case 0:
- setState(() {
- _bloc = CategoriaBloc(buildingId: _obra.id);
- title = _obra.nome;
- });
- break;
- case 1:
- setState(() {
- title = "Galeria";
- imageBloc.getImages(_obra.id);
- });
- break;
- case 2:
- setState(() {
- title = "Relatórios";
- });
- break;
- }
- bottomSelectedIndex = index;
- _pageCtrlCategorias.jumpToPage(index);
- });
- }
- void pageChanged(int index) {
- setState(() {
- bottomSelectedIndex = index;
- currentIndex = index;
- });
- }
- @override
- Widget build(BuildContext context) {
- return WillPopScope(
- child: Scaffold(
- body: PageView(
- controller: _pageCtrlCategorias,
- physics: NeverScrollableScrollPhysics(),
- children: <Widget>[
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: StreamBuilder<CategoriaState>(
- stream: _bloc.outState,
- builder: (context, snapshot) {
- if (snapshot.data == CategoriaState.LOADING)
- return _buildLoadingWidget();
- return _bloc.categorias.length > 0
- ? _createCardCategoria(_bloc.categorias)
- : Center(
- child: Container(
- padding: EdgeInsets.only(top: 10.0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Icon(Icons.cancel),
- Text("Nenhuma categoria foi encontrada!")
- ],
- ),
- ),
- );
- },
- )),
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: GaleriaPage(categorias: _bloc.categorias, obra: _obra),
- ),
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: RelatoriosPage(_obra))
- ],
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- setState(() async {
- if (currentIndex == 0) {
- await Navigator.of(context).push(MaterialPageRoute(
- builder: (context) => ListaCategoriasPage(_obra)));
- } else if (currentIndex == 2) {
- await Navigator.of(context).push(MaterialPageRoute(
- builder: (context) => AddRelatorioPage(),
- fullscreenDialog: true));
- }
- });
- },
- child: Icon(Icons.add),
- ),
- bottomNavigationBar: FABBottomAppBar(
- backgroundColor: Theme.of(context).primaryColor,
- color: Colors.white,
- selectedColor: Colors.yellow,
- onTabSelected: bottomTapped,
- notchedShape: CircularNotchedRectangle(),
- items: [
- FABBottomAppBarItem(iconData: Icons.photo_camera, text: 'Captura'),
- FABBottomAppBarItem(iconData: Icons.photo_library, text: 'Galeria'),
- FABBottomAppBarItem(
- iconData: Icons.insert_chart, text: 'Relatórios'),
- ],
- ),
- ),
- onWillPop: () {
- if (_pageCtrlCategorias.page != 0) {
- _pageCtrlCategorias.jumpToPage(0);
- setState(() {
- bottomSelectedIndex =
- int.parse(_pageCtrlCategorias.page.toString());
- currentIndex = int.parse(_pageCtrlCategorias.page.toString());
- });
- } else
- Navigator.of(context).pushReplacement(
- MaterialPageRoute(builder: (context) => HomePage("categoria")));
- },
- );
- }
- Widget _buildLoadingWidget() {
- return Shimmer.fromColors(
- baseColor: Colors.grey[300],
- highlightColor: Colors.grey[100],
- //enabled: snapshot.data.length,
- child: ListView.builder(
- padding: EdgeInsets.all(16.0),
- shrinkWrap: true,
- itemCount: 6,
- itemBuilder: (_, __) => Padding(
- padding: const EdgeInsets.only(bottom: 8.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Container(
- width: double.infinity,
- height: 8.0,
- color: Colors.white,
- ),
- const Padding(
- padding: EdgeInsets.symmetric(vertical: 2.0),
- ),
- Container(
- width: double.infinity,
- height: 8.0,
- color: Colors.white,
- ),
- const Padding(
- padding: EdgeInsets.symmetric(vertical: 2.0),
- ),
- Container(
- width: 40.0,
- height: 8.0,
- color: Colors.white,
- ),
- ],
- ),
- )
- ],
- ),
- ),
- ),
- );
- }
- Widget _createCardCategoria(List<Categoria> categorias) {
- return ListView.builder(
- padding: EdgeInsets.all(10.0),
- shrinkWrap: true,
- itemCount: categorias.length,
- itemBuilder: (context, index) {
- return categorias.length > 0
- ? GestureDetector(
- child: Card(
- clipBehavior: Clip.antiAlias,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- SizedBox(
- height: 124.0,
- child: Stack(
- children: <Widget>[
- DecoratedBox(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- colors: <Color>[Colors.black, Colors.black38],
- ),
- ),
- child: Image.asset(
- 'images/engenharia.jpg',
- color:
- const Color.fromRGBO(255, 255, 255, 0.190),
- colorBlendMode: BlendMode.modulate,
- fit: BoxFit.cover,
- width: double.infinity,
- ),
- ),
- Padding(
- padding: EdgeInsets.only(top: 70.0),
- child: Container(
- height: 60.0,
- color: Colors.black.withOpacity(0.2),
- ),
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(
- 16.0, 16.0, 16.0, 0.0),
- child: DefaultTextStyle(
- softWrap: false,
- overflow: TextOverflow.ellipsis,
- style: Theme.of(context).textTheme.subhead,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- // three line description
- Padding(
- padding: const EdgeInsets.only(
- bottom: 2.0, top: 63),
- child: Text(
- categorias[index].nome,
- style: Theme.of(context)
- .textTheme
- .title
- .copyWith(color: Colors.white),
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- onTap: () async {
- //await obraBloc.setActive(_obra);
- await Navigator.of(context).push(MaterialPageRoute(
- builder: (context) => CameraPage(categorias[index])));
- },
- )
- : Container();
- },
- );
- }
- Widget _buildPageView() {
- return WillPopScope(
- onWillPop: () {
- if (_pageCtrlCategorias.page != 0) {
- _pageCtrlCategorias.jumpToPage(0);
- setState(() {
- bottomSelectedIndex =
- int.parse(_pageCtrlCategorias.page.toString());
- currentIndex = int.parse(_pageCtrlCategorias.page.toString());
- });
- } else
- Navigator.of(context).pushReplacement(
- MaterialPageRoute(builder: (context) => HomePage("categoria")));
- },
- child: PageView(
- physics: NeverScrollableScrollPhysics(),
- controller: _pageCtrlCategorias,
- children: <Widget>[
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: _bloc.categorias.length > 0
- ? _createCardCategoria(_bloc.categorias)
- : Center(
- child: Container(
- padding: EdgeInsets.only(top: 10.0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Icon(Icons.cancel),
- Text("Nenhuma categoria foi encontrada!")
- ],
- ),
- ),
- ),
- ),
- //_createCardGaleria(data.results),
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: GaleriaPage(categorias: _bloc.categorias, obra: _obra),
- ),
- Scaffold(
- appBar: AppBar(
- title: Text(_obra.nome),
- centerTitle: true,
- ),
- drawer: DrawerPage(
- pageCtrl: _pageCtrl,
- ),
- body: RelatoriosPage(_obra))
- ],
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement