-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
391 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:pizzaria/src/shared/constants/app.dart'; | ||
import 'package:pizzaria/src/shared/controllers/order_controller.dart'; | ||
import 'package:pizzaria/src/shared/models/order_model.dart'; | ||
import 'package:pizzaria/src/views/admin/home/constants/home_admin.dart'; | ||
import 'package:pizzaria/src/views/admin/item/item_screen.dart'; | ||
import 'package:pizzaria/src/shared/controllers/auth_controller.dart'; | ||
import 'package:pizzaria/src/shared/themes/colors/color_schemes.g.dart'; | ||
import 'package:pizzaria/src/shared/services/util_service.dart'; | ||
import 'package:pizzaria/src/views/admin/user/user_screen.dart'; | ||
import 'package:stomp_dart_client/stomp.dart'; | ||
import 'package:stomp_dart_client/stomp_config.dart'; | ||
import 'package:stomp_dart_client/stomp_frame.dart'; | ||
|
||
class HomeAdminScreen extends StatefulWidget { | ||
const HomeAdminScreen({super.key}); | ||
|
||
@override | ||
State<HomeAdminScreen> createState() => _HomeAdminScreenState(); | ||
} | ||
|
||
class _HomeAdminScreenState extends State<HomeAdminScreen> { | ||
late StompClient stompClient; | ||
|
||
void onConnect(StompClient stompClient, StompFrame stompFrame) { | ||
stompClient.subscribe( | ||
destination: '/topic/message', | ||
callback: (frame) { | ||
if (frame.body != null) { | ||
setState(() {}); | ||
} | ||
}); | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
stompClient = StompClient( | ||
config: StompConfig.SockJS( | ||
url: "${AppConstants.baseUrl}/ws-message", | ||
onConnect: (stompFrame) => onConnect(stompClient, stompFrame), | ||
), | ||
); | ||
|
||
stompClient.activate(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final utilService = UtilService(); | ||
final authController = AuthController(); | ||
final orderController = OrderController(); | ||
return Scaffold( | ||
//Appbar | ||
appBar: AppBar( | ||
title: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
const Text( | ||
"Painel administrativo", | ||
), | ||
IconButton( | ||
onPressed: () async { | ||
authController.signOut(); | ||
}, | ||
icon: const Icon( | ||
Icons.logout, | ||
), | ||
) | ||
], | ||
), | ||
), | ||
|
||
//Body | ||
body: Column( | ||
children: [ | ||
Expanded( | ||
child: GridView.count( | ||
crossAxisSpacing: 0, | ||
crossAxisCount: MediaQuery.of(context).size.width < 800 ? 2 : 6, | ||
children: List.generate( | ||
HomeAdmin.labels.length, | ||
(index) => Padding( | ||
padding: const EdgeInsets.all(6.0), | ||
|
||
//Containers menu | ||
child: GestureDetector( | ||
onTap: () => index.isEqual(1) | ||
? Get.to(const ItemAdminScreen()) | ||
: index.isEqual(0) | ||
? Get.to(const UserAdminScreen()) | ||
: null, | ||
child: Container( | ||
decoration: BoxDecoration( | ||
border: Border.all( | ||
color: lightColorScheme.primary, | ||
), | ||
color: lightColorScheme.background, | ||
borderRadius: BorderRadius.circular(12), | ||
), | ||
|
||
//Title, icon, description | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
CircleAvatar( | ||
maxRadius: | ||
utilService.screenDeviceWidth(13, 30, context), | ||
child: Icon(HomeAdmin.icons[index]), | ||
), | ||
const SizedBox(height: 10), | ||
Text(HomeAdmin.labels[index]), | ||
Text( | ||
HomeAdmin.description[index], | ||
style: TextStyle(color: Colors.grey.shade500), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
|
||
//Orders | ||
const Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Row( | ||
children: [ | ||
Text( | ||
'Pedidos em andamento', | ||
style: TextStyle(fontSize: 32), | ||
), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: FutureBuilder( | ||
future: orderController.get(), | ||
builder: (context, snapshot) { | ||
if (!snapshot.hasData) { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
|
||
return ListView.separated( | ||
separatorBuilder: (context, index) => const Divider(), | ||
itemCount: snapshot.data!.length, | ||
itemBuilder: (context, index) { | ||
final orderModel = | ||
OrderModel.fromMap(snapshot.data?[index] ?? {}); | ||
|
||
//List oreder | ||
return ListTile( | ||
//ID | ||
title: Text(orderModel.id!), | ||
|
||
//Items in order | ||
subtitle: Row( | ||
children: List.generate( | ||
orderModel.item!.length, | ||
(index) => | ||
Text("+ ${orderModel.item![index]['name']} ")), | ||
), | ||
|
||
//Total price | ||
trailing: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
utilService.convertToBRL(orderModel.total ?? 0), | ||
style: const TextStyle(fontSize: 16), | ||
), | ||
IconButton( | ||
onPressed: () async { | ||
await orderController.delete(id: orderModel.id!); | ||
setState(() {}); | ||
}, | ||
icon: const Icon( | ||
Icons.delete, | ||
color: Colors.red, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
stompClient.deactivate(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:pizzaria/src/views/admin/item/item_details_screen.dart'; | ||
import 'package:pizzaria/src/views/admin/item/widgets/additem.dart'; | ||
import 'package:pizzaria/src/shared/services/util_service.dart'; | ||
import 'package:pizzaria/src/shared/controllers/item_controller.dart'; | ||
import 'package:pizzaria/src/shared/models/item_model.dart'; | ||
import 'package:pizzaria/src/shared/themes/colors/color_schemes.g.dart'; | ||
import 'package:pizzaria/src/widgets/progress_custom.dart'; | ||
|
||
class ItemAdminScreen extends StatefulWidget { | ||
const ItemAdminScreen({super.key}); | ||
|
||
@override | ||
State<ItemAdminScreen> createState() => _ItemAdminScreenState(); | ||
} | ||
|
||
class _ItemAdminScreenState extends State<ItemAdminScreen> { | ||
final itemController = ItemController(); | ||
final utilService = UtilService(); | ||
|
||
@override | ||
void initState() { | ||
itemController.addListener(() => setState(() {})); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text("Gerenciamento de itens"), | ||
), | ||
body: StreamBuilder( | ||
stream: itemController.getLikeStream(), | ||
builder: (context, snapshot) { | ||
//Progress data. | ||
if (!snapshot.hasData) { | ||
return const ProgressCustom( | ||
height: 25, | ||
width: 25, | ||
); | ||
} | ||
|
||
//List items | ||
return ListView.separated( | ||
itemBuilder: (context, index) { | ||
//Constructor item model. | ||
final itemModel = | ||
ItemModel.fromMap(snapshot.data?[index] ?? {}); | ||
|
||
return GestureDetector( | ||
onTap: () => Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => ItemAdminDetailsScreen( | ||
itemModel: itemModel, | ||
), | ||
), | ||
), | ||
child: ListTile( | ||
title: Text(itemModel.name!), | ||
subtitle: Text( | ||
itemModel.description ?? "Não há descrição neste item"), | ||
trailing: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
//Price | ||
IconButton( | ||
onPressed: () {}, | ||
icon: Text( | ||
utilService.convertToBRL(itemModel.price!), | ||
), | ||
), | ||
//Delete | ||
IconButton( | ||
onPressed: () async { | ||
await itemController.delete(itemModel.id!); | ||
}, | ||
icon: Icon( | ||
Icons.delete, | ||
color: lightColorScheme.error, | ||
), | ||
) | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
separatorBuilder: (context, index) => const Divider(), | ||
itemCount: snapshot.data?.length ?? 0); | ||
}, | ||
), | ||
|
||
//Add items | ||
floatingActionButton: FloatingActionButton.extended( | ||
onPressed: () { | ||
showDialog( | ||
context: context, | ||
builder: (context) => const Column( | ||
mainAxisSize: MainAxisSize.min, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
AddItemWindow(), | ||
], | ||
), | ||
); | ||
}, | ||
label: const Text("Adicionar"), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.