import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "main.dart";

//String ergebnis="nein";

class DatumZeit {
  var datum;
  var zeit;

  DatumZeit(this.datum, this.zeit);
}

class FormDateTimeSet extends StatefulWidget {
  const FormDateTimeSet({super.key});

  //Daran muß garbeitet werden!!!!
  //final ValueChanged <DatumZeit> ergebnis;
  //FormDateTimeSet(this.datumString, {super.key, required this.ergebnis});
 // FormDateTimeSet({super.key});

  @override
  State<FormDateTimeSet> createState() => _FormDateTimeSetState();
}

class _FormDateTimeSetState extends State<FormDateTimeSet> {
/*
  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }
  */
  @override
  Widget build(BuildContext context) {
    var ergebnis = ModalRoute.of(context)!.settings.arguments as DatumZeit;
    DateTime dateTime = DateTime(2016, 8, 3, 17, 45);
    context:
    context;
    final size = MediaQuery.of(context).size;
    return Scaffold(
        //var ergebnis = ModalRoute.of(context)!.settings.arguments as String;
        body: Form(
      child: Column(
        children: <Widget>[
          Container(
            //child: Form(
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20),
                topRight: Radius.circular(20),
              ),
            ),
            height: size.height * 0.27,
            // child: Column (
            // children: <Widget>[

            //children: <Widget>[
            child: CupertinoDatePicker(

              mode: CupertinoDatePickerMode.date,
              onDateTimeChanged: (value) {
                //date = value;
                dateTime = value;
                setState(() {});
              },
            ),
            // child: Text("Hallo test"),

            // ],
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: () {
                    ergebnis.datum = "ok";
                    Navigator.pop(context, dateTime);
                  },
                  child: Text(context.sp.ok),
                ),
                ElevatedButton(
                  onPressed: () {
                    //datumString="abbruch";
                    ergebnis.datum = "abbruch";
                    Navigator.pop(context, null);
                  },
                  child: Text(context.sp.abbruch),
                ),
              ],
            ),
          ),
          Container(
            child: Text(
                "${dateTime.month}-${dateTime.day}-${dateTime.day}-${dateTime.year}"),
          ),
        ],
        /*
      padding: EdgeInsets.all(10),
      child: CupertinoDatePicker(
          initialDateTime: dateTime,
          use24hFormat: true,
          // This is called when the user changes the dateTime.
          onDateTimeChanged: (DateTime newDateTime) {
            setState(() => dateTime = newDateTime);
          },
        ),

      */
      ),
    ));
  }
}
