|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import '../rag_demo_data.dart'; |
| 3 | +import 'sample_documents_screen.dart'; |
| 4 | + |
| 5 | +class KnowledgeBaseSection extends StatelessWidget { |
| 6 | + final bool isLoading; |
| 7 | + final int addTimeMs; |
| 8 | + final VoidCallback onAddDocuments; |
| 9 | + final VoidCallback onClearDocuments; |
| 10 | + |
| 11 | + const KnowledgeBaseSection({ |
| 12 | + super.key, |
| 13 | + required this.isLoading, |
| 14 | + required this.addTimeMs, |
| 15 | + required this.onAddDocuments, |
| 16 | + required this.onClearDocuments, |
| 17 | + }); |
| 18 | + |
| 19 | + @override |
| 20 | + Widget build(BuildContext context) { |
| 21 | + return Column( |
| 22 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 23 | + children: [ |
| 24 | + const Text( |
| 25 | + 'Knowledge Base', |
| 26 | + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), |
| 27 | + ), |
| 28 | + const SizedBox(height: 12), |
| 29 | + |
| 30 | + // Buttons |
| 31 | + Row( |
| 32 | + children: [ |
| 33 | + Expanded( |
| 34 | + child: ElevatedButton.icon( |
| 35 | + onPressed: isLoading |
| 36 | + ? null |
| 37 | + : () { |
| 38 | + Navigator.push( |
| 39 | + context, |
| 40 | + MaterialPageRoute<void>( |
| 41 | + builder: (context) => SampleDocumentsScreen( |
| 42 | + onAddDocuments: onAddDocuments, |
| 43 | + isLoading: isLoading, |
| 44 | + ), |
| 45 | + ), |
| 46 | + ); |
| 47 | + }, |
| 48 | + icon: const Icon(Icons.add), |
| 49 | + label: Text('Add ${sampleDocuments.length} Docs'), |
| 50 | + ), |
| 51 | + ), |
| 52 | + const SizedBox(width: 8), |
| 53 | + Expanded( |
| 54 | + child: ElevatedButton.icon( |
| 55 | + onPressed: isLoading ? null : onClearDocuments, |
| 56 | + icon: const Icon(Icons.delete), |
| 57 | + label: const Text('Clear All'), |
| 58 | + style: ElevatedButton.styleFrom( |
| 59 | + backgroundColor: Colors.red.shade900, |
| 60 | + foregroundColor: Colors.white, |
| 61 | + ), |
| 62 | + ), |
| 63 | + ), |
| 64 | + ], |
| 65 | + ), |
| 66 | + if (addTimeMs > 0) |
| 67 | + Padding( |
| 68 | + padding: const EdgeInsets.only(top: 4), |
| 69 | + child: Text( |
| 70 | + 'Last add: ${addTimeMs}ms', |
| 71 | + style: const TextStyle(fontSize: 12, color: Colors.grey), |
| 72 | + ), |
| 73 | + ), |
| 74 | + ], |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments