@@ -11,6 +11,7 @@ import 'dashboard_controller.dart';
1111import 'package:http/http.dart' as http;
1212import 'package:mapos_app/providers/theme_provider.dart' ;
1313import 'package:provider/provider.dart' ;
14+ import 'package:mapos_app/pages/os/os_view_page.dart' ;
1415
1516class DashboardPage extends StatefulWidget {
1617 @override
@@ -88,6 +89,50 @@ class _DashboardPageState extends State<DashboardPage> {
8889 }
8990 }
9091
92+ void _navigateToOsView (String osNumber) {
93+ if (osNumber.isEmpty) {
94+ ScaffoldMessenger .of (context).showSnackBar (
95+ const SnackBar (
96+ content: Text ('Por favor, digite um número de OS válido' ),
97+ backgroundColor: Colors .red,
98+ ),
99+ );
100+ return ;
101+ }
102+
103+ // Verifica se o número contém apenas dígitos
104+ if (! RegExp (r'^\d+$' ).hasMatch (osNumber)) {
105+ ScaffoldMessenger .of (context).showSnackBar (
106+ const SnackBar (
107+ content: Text ('O número da OS deve conter apenas dígitos' ),
108+ backgroundColor: Colors .red,
109+ ),
110+ );
111+ return ;
112+ }
113+
114+ final osId = int .tryParse (osNumber);
115+ if (osId == null ) {
116+ ScaffoldMessenger .of (context).showSnackBar (
117+ const SnackBar (
118+ content: Text ('Número de OS inválido' ),
119+ backgroundColor: Colors .red,
120+ ),
121+ );
122+ return ;
123+ }
124+
125+ // Navega para a página de visualização da OS
126+ Navigator .push (
127+ context,
128+ MaterialPageRoute (
129+ builder: (context) => VisualizarOrdemServicoPage (idOrdemServico: osId),
130+ ),
131+ ).then ((_) {
132+ // Atualiza o dashboard quando retornar da visualização da OS
133+ _loadDashboardData ();
134+ });
135+ }
91136 @override
92137 Widget build (BuildContext context) {
93138 final themeProvider = Provider .of <ThemeProvider >(context, listen: false );
@@ -177,26 +222,38 @@ class _DashboardPageState extends State<DashboardPage> {
177222 }
178223
179224 Widget _buildSearchField () {
225+ final TextEditingController _osSearchController = TextEditingController ();
226+
180227 return Container (
181228 padding: const EdgeInsets .symmetric (horizontal: 16 ),
182229 decoration: BoxDecoration (
183- color: Colors .white ,
230+ color: Theme . of (context).cardColor ,
184231 borderRadius: BorderRadius .circular (8 ),
185- boxShadow: const [
232+ boxShadow: [
186233 BoxShadow (
187- color: Colors .black12 ,
234+ color: Colors .black. withOpacity ( 0.1 ) ,
188235 blurRadius: 6 ,
189- offset: Offset (0 , 2 ),
236+ offset: const Offset (0 , 2 ),
190237 ),
191238 ],
192239 ),
193- child: const TextField (
240+ child: TextField (
241+ controller: _osSearchController,
194242 decoration: InputDecoration (
195243 border: InputBorder .none,
196- hintText: 'Digite o numero de uma OS' ,
197- icon: Icon (Icons .search),
244+ hintText: 'Digite o número de uma OS' ,
245+ icon: const Icon (Icons .search),
246+ suffixIcon: IconButton (
247+ icon: const Icon (Icons .arrow_forward),
248+ onPressed: () {
249+ _navigateToOsView (_osSearchController.text);
250+ },
251+ ),
198252 ),
199253 keyboardType: TextInputType .number,
254+ onSubmitted: (value) {
255+ _navigateToOsView (value);
256+ },
200257 ),
201258 );
202259 }
0 commit comments