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

View file

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

View file

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