[chore] automatic dart cleanup

This commit is contained in:
Mercurio 2023-11-10 08:32:53 +01:00
parent f205a2e5ac
commit 678865b967
3 changed files with 32 additions and 26 deletions

View file

@ -2,18 +2,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert'; import 'dart:convert';
import 'package:OpenshockCompanion/api_handler.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class SettingsPage extends StatelessWidget { class SettingsPage extends StatelessWidget {
final TextEditingController apiKeyController = TextEditingController(); final TextEditingController apiKeyController = TextEditingController();
final TextEditingController shockerIdController = TextEditingController(); final TextEditingController shockerIdController = TextEditingController();
SettingsPage({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Settings'), title: const Text('Settings'),
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
@ -22,14 +23,14 @@ class SettingsPage extends StatelessWidget {
children: [ children: [
TextField( TextField(
controller: apiKeyController, controller: apiKeyController,
decoration: InputDecoration(labelText: 'API Key'), decoration: const InputDecoration(labelText: 'API Key'),
), ),
TextField( TextField(
controller: shockerIdController, controller: shockerIdController,
decoration: InputDecoration(labelText: 'Shocker ID'), decoration: const InputDecoration(labelText: 'Shocker ID'),
), ),
ElevatedButton( // Updated from RaisedButton to ElevatedButton ElevatedButton( // Updated from RaisedButton to ElevatedButton
child: Text('Save and Login'), child: const Text('Save and Login'),
onPressed: () { onPressed: () {
saveSettings(apiKeyController.text, shockerIdController.text); saveSettings(apiKeyController.text, shockerIdController.text);
Navigator.pop(context); Navigator.pop(context);

View file

@ -5,10 +5,12 @@ import 'package:OpenshockCompanion/api_handler.dart' show sendApiRequest;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
void main() { void main() {
runApp(MyApp()); runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<bool>( return FutureBuilder<bool>(
@ -19,7 +21,7 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
theme: isDarkMode ? darkTheme : lightTheme, theme: isDarkMode ? darkTheme : lightTheme,
home: SliderPage(), home: const SliderPage(),
darkTheme: darkTheme, darkTheme: darkTheme,
themeMode: ThemeMode.system, // Use ThemeMode.dark for always dark mode, ThemeMode.light for always light mode themeMode: ThemeMode.system, // Use ThemeMode.dark for always dark mode, ThemeMode.light for always light mode
); );
@ -34,6 +36,8 @@ class MyApp extends StatelessWidget {
} }
class SliderPage extends StatefulWidget { class SliderPage extends StatefulWidget {
const SliderPage({super.key});
@override @override
_SliderPageState createState() => _SliderPageState(); _SliderPageState createState() => _SliderPageState();
} }
@ -46,7 +50,7 @@ class _SliderPageState extends State<SliderPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Openshock Companion'), title: const Text('Openshock Companion'),
), ),
body: Align( body: Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
@ -81,8 +85,8 @@ class _SliderPageState extends State<SliderPage> {
}, },
), ),
if (intensityValue < 1 || timeValue < 1) if (intensityValue < 1 || timeValue < 1)
Padding( const Padding(
padding: const EdgeInsets.only(top: 16.0), padding: EdgeInsets.only(top: 16.0),
child: Text( child: Text(
'Warning: Intensity and time values must be at least 1', 'Warning: Intensity and time values must be at least 1',
style: TextStyle(color: Colors.red), style: TextStyle(color: Colors.red),
@ -92,8 +96,8 @@ class _SliderPageState extends State<SliderPage> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
ElevatedButton.icon( ElevatedButton.icon(
icon: Icon(Icons.flash_on), // Lightning bolt icon icon: const Icon(Icons.flash_on), // Lightning bolt icon
label: Text('Shock'), label: const Text('Shock'),
onPressed: () { onPressed: () {
if (intensityValue < 1 || timeValue < 1) { if (intensityValue < 1 || timeValue < 1) {
// Display a warning, no need for a toast // Display a warning, no need for a toast
@ -103,10 +107,10 @@ class _SliderPageState extends State<SliderPage> {
} }
}, },
), ),
SizedBox(width: 8.0), // Reduced padding here const SizedBox(width: 8.0), // Reduced padding here
ElevatedButton.icon( ElevatedButton.icon(
icon: Icon(Icons.vibration), // Vibration icon icon: const Icon(Icons.vibration), // Vibration icon
label: Text('Vibrate'), label: const Text('Vibrate'),
onPressed: () { onPressed: () {
if (intensityValue < 1 || timeValue < 1) { if (intensityValue < 1 || timeValue < 1) {
// Display a warning, no need for a toast // Display a warning, no need for a toast
@ -119,11 +123,11 @@ class _SliderPageState extends State<SliderPage> {
], ],
), ),
ElevatedButton( ElevatedButton(
child: Text('Settings'), child: const Text('Settings'),
onPressed: () { onPressed: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => SettingsPage()), MaterialPageRoute(builder: (context) => const SettingsPage()),
); );
}, },
), ),

View file

@ -1,9 +1,10 @@
// settings_page.dart // settings_page.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:OpenshockCompanion/api_handler.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class SettingsPage extends StatefulWidget { class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@override @override
_SettingsPageState createState() => _SettingsPageState(); _SettingsPageState createState() => _SettingsPageState();
} }
@ -43,14 +44,14 @@ class _SettingsPageState extends State<SettingsPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Settings'), title: const Text('Settings'),
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('API Key'), const Text('API Key'),
TextField( TextField(
controller: apiKeyController, controller: apiKeyController,
decoration: InputDecoration( decoration: InputDecoration(
@ -66,8 +67,8 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
obscureText: !showApiKey, obscureText: !showApiKey,
), ),
SizedBox(height: 16), const SizedBox(height: 16),
Text('Shocker ID'), const Text('Shocker ID'),
TextField( TextField(
controller: shockerIdController, controller: shockerIdController,
decoration: InputDecoration( decoration: InputDecoration(
@ -83,10 +84,10 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
obscureText: !showShockerId, obscureText: !showShockerId,
), ),
SizedBox(height: 16), const SizedBox(height: 16),
Row( Row(
children: [ children: [
Text('Dark Mode'), const Text('Dark Mode'),
Switch( Switch(
value: isDarkMode, value: isDarkMode,
onChanged: (value) { onChanged: (value) {
@ -97,10 +98,10 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
], ],
), ),
SizedBox(height: 16), const SizedBox(height: 16),
ElevatedButton( ElevatedButton(
child: Text('Save'),
onPressed: saveSettingsAndTheme, onPressed: saveSettingsAndTheme,
child: const Text('Save'),
), ),
], ],
), ),