import 'package:flutter/material.dart'; import 'package:mobdr/main.dart'; import 'package:mobdr/config/global_style.dart'; import 'package:mobdr/ui/reusable/reusable_widget.dart'; import 'package:mobdr/db/box_log.dart'; class LogPage extends StatefulWidget { @override _LogPageState createState() => _LogPageState(); } class _LogPageState extends State { final _reusableWidget = ReusableWidget(); Widget Function(BuildContext, int) _itemBuilder(List logs) => (BuildContext context, int index) => Row( children: [ Expanded( child: Container( decoration: const BoxDecoration( border: Border(bottom: BorderSide(color: Colors.black12)), ), child: Padding( padding: const EdgeInsets.symmetric( vertical: 18.0, horizontal: 10.0, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( logs[index].libelle, style: const TextStyle( fontSize: 15.0, ), // Provide a Key for the integration test key: Key('list_log_$index'), ), Padding( padding: const EdgeInsets.only(top: 5.0), child: Text( 'Added on ${logs[index].dateFormat}', style: const TextStyle( fontSize: 12.0, ), ), ), ], ), ), ), ), ], ); @override void initState() { super.initState(); } @override void dispose() { super.dispose(); } void _showConfirmationDialog() { showDialog( context: context, builder: (context) => AlertDialog( title: Text('Confirmation'), content: Text('Are you sure you want to delete this log?'), actions: [ TextButton( child: Text('Cancel'), onPressed: () { Navigator.of(context).pop(); }, ), TextButton( child: Text('Delete'), onPressed: () { // remove all log from db objectbox.logBox.removeAll(); // close dialog Navigator.of(context).pop(); }, ), ], ), ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( iconTheme: IconThemeData( color: GlobalStyle.appBarIconThemeColor, ), elevation: GlobalStyle.appBarElevation, title: Text( 'Show logs', style: GlobalStyle.appBarTitle, ), backgroundColor: GlobalStyle.appBarBackgroundColor, systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle, actions: [ IconButton( icon: Icon(Icons.delete), onPressed: _showConfirmationDialog, ), ], bottom: _reusableWidget.bottomAppBar(), ), body: Column( children: [ Expanded( child: StreamBuilder>( stream: objectbox.getLogs(), builder: (context, snapshot) => ListView.builder( shrinkWrap: true, padding: const EdgeInsets.symmetric(horizontal: 20.0), itemCount: snapshot.hasData ? snapshot.data!.length : 0, itemBuilder: _itemBuilder(snapshot.data ?? []), ), ), ), ], ), ); } }