From 151cb9e6db153921b8acf576f0bcc5c1118c6161 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 29 Dec 2023 21:11:16 +0100 Subject: [PATCH] Slider integrated with Text --- emma/lib/main.dart | 77 ++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/emma/lib/main.dart b/emma/lib/main.dart index 3edffd4..788fb88 100644 --- a/emma/lib/main.dart +++ b/emma/lib/main.dart @@ -1,10 +1,11 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({super.key}); + //const MyApp({super.key}); // This widget is the root of your application. @@ -32,13 +33,13 @@ class MyApp extends StatelessWidget { useMaterial3: true, primaryColor: Colors.lightBlue, ), - home: MyFormPage(title: 'Flutter Formular'), + home: const MyFormPage(title: 'Flutter Formular'), ); } } class MyFormPage extends StatefulWidget { - MyFormPage({Key key = const Key('defaultKey'), required this.title}) + const MyFormPage({Key key = const Key('defaultKey'), required this.title}) : super(key: key); final String title; @override @@ -52,6 +53,7 @@ class _MyFormPageState extends State { } final _formKey = GlobalKey(); + double _currentSliderValue = 20; @override Widget build(BuildContext context) { return Scaffold( @@ -69,8 +71,8 @@ class _MyFormPageState extends State { TextFormField( keyboardType: TextInputType.text, autocorrect: false, - decoration: InputDecoration( - labelText: 'Benutzername', + decoration: const InputDecoration( + labelText: 'Wohin solls gehen?', border: OutlineInputBorder(), ), validator: (value) { @@ -80,62 +82,57 @@ class _MyFormPageState extends State { return null; }, ), - SizedBox(height: 20), + const SizedBox(height: 20), TextFormField( keyboardType: TextInputType.emailAddress, - decoration: InputDecoration( - labelText: 'E-Mail', + decoration: const InputDecoration( + labelText: 'GPS: Hier bin ich', border: OutlineInputBorder(), ), ), - SizedBox(height: 20), + const SizedBox(height: 20), TextFormField( obscureText: true, - decoration: InputDecoration( - labelText: 'Passwort', + decoration: const InputDecoration( + labelText: 'Punkt auf der Karte', border: OutlineInputBorder(), ), ), - SizedBox(height: 20), - TextFormField( - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: 'Lieblingszahl', - border: OutlineInputBorder(), - ), - validator: zahlValidator, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, - ], + const SizedBox(height: 20), + Text( + "Umkreis von " + + _currentSliderValue.floor().toString() + + " km", + style: TextStyle(fontSize: 20), ), - SizedBox(height: 20), - TextFormField( - maxLines: 5, - maxLength: 120, - decoration: InputDecoration( - hintText: 'Freitext', - border: OutlineInputBorder(), - ), - ), - SizedBox(height: 40), + Slider( + value: _currentSliderValue, + max: 100, + divisions: 5, + label: _currentSliderValue.round().toString() + " km", + onChanged: (double value) { + setState(() { + _currentSliderValue = value; + }); + }), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( style: ElevatedButton.styleFrom( - primary: Colors.grey, - textStyle: TextStyle(color: Colors.white)), + backgroundColor: Colors.grey, + textStyle: const TextStyle(color: Colors.white)), onPressed: () { // reset() setzt alle Felder wieder auf den Initalwert zurück. _formKey.currentState?.reset(); }, - child: Text('Löschen'), + child: const Text('Löschen'), ), - SizedBox(width: 25), + const SizedBox(width: 25), ElevatedButton( style: ElevatedButton.styleFrom( - primary: Colors.blue, - textStyle: TextStyle(color: Colors.white)), + backgroundColor: Colors.blue, + textStyle: const TextStyle(color: Colors.white)), onPressed: () { // Wenn alle Validatoren der Felder des Formulars gültig sind. if (_formKey.currentState!.validate()) { @@ -145,7 +142,7 @@ class _MyFormPageState extends State { print("Formular ist nicht gültig"); } }, - child: Text('Speichern'), + child: const Text('Speichern'), ) ], )