From 5f5487803b8ce847794d284b330ef218da75eeee Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 15 Sep 2024 17:49:50 +0200 Subject: [PATCH] refactor --- lib/pages/consume.dart | 6 ++---- lib/pages/itemview.dart | 37 +++++++++++++++++++------------------ lib/pages/setup.dart | 21 +++++++++++---------- lib/pages/supply.dart | 6 +++--- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/pages/consume.dart b/lib/pages/consume.dart index ed199c2..231c528 100644 --- a/lib/pages/consume.dart +++ b/lib/pages/consume.dart @@ -1,15 +1,13 @@ import 'package:cdb_ui/api.dart'; import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; -import 'supply.dart'; class ConsumePage extends StatefulWidget { final String item; final String variant; final String transaction; - Function refresh; + final Function refresh; - ConsumePage(this.transaction, this.item, this.variant, this.refresh, + const ConsumePage(this.transaction, this.item, this.variant, this.refresh, {super.key}); @override diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index 147a3cb..94bf1e9 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -26,7 +26,7 @@ class _ItemViewState extends State { ), body: Column(children: [ Padding( - padding: EdgeInsets.symmetric(horizontal: 28), + padding: const EdgeInsets.symmetric(horizontal: 28), child: Column( children: [ Row( @@ -39,7 +39,7 @@ class _ItemViewState extends State { fallbackHeight: 100, ), ), // todo - SizedBox( + const SizedBox( width: 16.0, ), Column( @@ -60,13 +60,13 @@ class _ItemViewState extends State { return Column(children: [ Text( entry.value.name, - style: TextStyle(fontWeight: FontWeight.bold), + style: const TextStyle(fontWeight: FontWeight.bold), ), FutureBuilder( future: API().getStat(widget.item.id, entry.key), builder: (context, snapshot) { if (!snapshot.hasData) { - return CircularProgressIndicator(); + return const CircularProgressIndicator(); } var stat = snapshot.data!; @@ -82,7 +82,7 @@ class _ItemViewState extends State { ) ]); }).toList()), - SizedBox( + const SizedBox( height: 12, ) ], @@ -115,9 +115,9 @@ class _ItemViewState extends State { class TransactionCard extends StatelessWidget { final Transaction t; - Function refresh; + final Function refresh; - TransactionCard(this.t, this.refresh, {super.key}); + const TransactionCard(this.t, this.refresh, {super.key}); @override Widget build(BuildContext context) { @@ -131,13 +131,13 @@ class TransactionCard extends StatelessWidget { }, child: Card( color: t.expired ? Colors.red[100] : Colors.black, - margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16), + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), elevation: 4, child: Padding( - padding: EdgeInsets.all(12), + padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -148,9 +148,9 @@ class TransactionCard extends StatelessWidget { children: [ Text( t.item, - style: TextStyle(fontSize: 16), + style: const TextStyle(fontSize: 16), ), - SizedBox( + const SizedBox( width: 4, ), Text( @@ -165,25 +165,26 @@ class TransactionCard extends StatelessWidget { ), ], ), - SizedBox( + const SizedBox( height: 10, ), Row( children: [ - Icon(Icons.money, size: 18, color: Colors.green), - SizedBox(width: 6), + const Icon(Icons.money, size: 18, color: Colors.green), + const SizedBox(width: 6), Text( "${t.price.value.toStringAsFixed(2)} ${t.price.currency}", - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + style: const TextStyle( + fontSize: 16, fontWeight: FontWeight.bold), ), ], ), if (t.origin != null) ...[ - SizedBox(height: 8), + const SizedBox(height: 8), Row( children: [ - Icon(Icons.store, size: 18, color: Colors.blue), - SizedBox(width: 6), + const Icon(Icons.store, size: 18, color: Colors.blue), + const SizedBox(width: 6), Text( t.origin!, style: TextStyle(fontSize: 14, color: Colors.grey[700]), diff --git a/lib/pages/setup.dart b/lib/pages/setup.dart index 3c7d6ed..d95944c 100644 --- a/lib/pages/setup.dart +++ b/lib/pages/setup.dart @@ -1,9 +1,10 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/main.dart'; import 'package:flutter/material.dart'; -import 'package:shared_preferences/shared_preferences.dart'; class SetupPage extends StatefulWidget { + const SetupPage({super.key}); + @override _SetupPageState createState() => _SetupPageState(); } @@ -18,7 +19,7 @@ class _SetupPageState extends State { if (instanceUrl.isEmpty || token.isEmpty) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Please fill in all fields')), + const SnackBar(content: Text('Please fill in all fields')), ); return; } @@ -27,14 +28,14 @@ class _SetupPageState extends State { // Indicate that the setup is complete ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Setup Complete!')), + const SnackBar(content: Text('Setup Complete!')), ); // Navigate or close the setup screen Navigator.pushReplacement( context, MaterialPageRoute( - builder: (context) => MyHomePage(), + builder: (context) => const MyHomePage(), )); } @@ -42,7 +43,7 @@ class _SetupPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Setup Page'), + title: const Text('Setup Page'), ), body: Padding( padding: const EdgeInsets.all(16.0), @@ -50,19 +51,19 @@ class _SetupPageState extends State { children: [ TextField( controller: _urlController, - decoration: InputDecoration(labelText: 'Instance URL'), + decoration: const InputDecoration(labelText: 'Instance URL'), keyboardType: TextInputType.url, ), - SizedBox(height: 16.0), + const SizedBox(height: 16.0), TextField( controller: _tokenController, - decoration: InputDecoration(labelText: 'Token'), + decoration: const InputDecoration(labelText: 'Token'), obscureText: true, ), - SizedBox(height: 32.0), + const SizedBox(height: 32.0), ElevatedButton( onPressed: _saveSettings, - child: Text('Complete Setup'), + child: const Text('Complete Setup'), ), ], ), diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index b3de61b..aa254c0 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -4,9 +4,9 @@ import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class SupplyPage extends StatefulWidget { final Item item; - Function refresh; + final Function refresh; - SupplyPage(this.item, this.refresh, {super.key}); + const SupplyPage(this.item, this.refresh, {super.key}); @override State createState() => _SupplyPageState(); @@ -168,7 +168,7 @@ class _SupplyPageState extends State { }, ), ), - SizedBox( + const SizedBox( width: 12, ), IconButton(