import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'sidebar.dart';

class Settings extends StatefulWidget {
  const Settings({Key? key}) : super(key: key);

  static const initIp = "";

  static var ip = initIp;

  static const initPort = "";

  static var port = initPort;

  static SharedPreferences? preferencesInstance;

  @override
  State<Settings> createState() => _SettingsState();

  /// Initializes the Settings with the correct Values from the last session
  static Future initSettings() async {
  }
}

class _SettingsState extends State<Settings> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: const Text("Settings"),
        ),
        body: Center(
          child: Column(
            children: [
              TextFormField(
                decoration: const InputDecoration(
                    labelText: "Address for the Classifier-Server"),
                initialValue: Settings.ip,
                onChanged: (String newValue) {
                  Settings.ip = newValue;
                  Settings.preferencesInstance?.setString("IP", newValue);
                },
              ),
              TextFormField(
                decoration: const InputDecoration(
                    labelText: "Port for the Classifier-Server"),
                keyboardType: TextInputType.number,
                inputFormatters: <TextInputFormatter>[
                  FilteringTextInputFormatter.digitsOnly
                ],
                initialValue: Settings.port,
                onChanged: (String newValue) {
                  Settings.port = newValue;
                  Settings.preferencesInstance?.setString("Port", newValue);
                },
              )
            ],
          ),
        ),
        drawer: const Sidebar());
  }
}
