import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:aman_kassa_flutter/core/logger.dart';
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
import 'package:aman_kassa_flutter/redux/store.dart';

import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide Image;
import 'package:flutter/rendering.dart';


import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
import 'package:intl/intl.dart';
import 'package:logger/logger.dart';

import '../data/settings_envi.dart';


class PrinterEncodingView extends StatefulWidget {
  PrinterEncodingView({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _PrinterEncodingViewState createState() => _PrinterEncodingViewState();

}

class _PrinterEncodingViewState extends State<PrinterEncodingView> {

  Logger _logger = getLogger('PrinterEncodingView');

  @override
  void initState() {
    super.initState();
  }





  void _selectPrinter(String encoding, BuildContext context, ) async {
    _logger.i(encoding);
    await Redux.store.dispatch(selectPrinterEncodingFromSetting(encoding));
    Navigator.of(context).pop(false);
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Выберите кодировку'),
      ),
      body: ListView.builder(
          itemCount: encoding.keys.length,
          itemBuilder: (BuildContext _, int index) {
            return InkWell(
              onTap: () => _selectPrinter(encoding.keys.elementAt(index), context),
              child: Column(
                children: <Widget>[
                  Container(
                    height: 60,
                    padding: EdgeInsets.only(left: 10),
                    alignment: Alignment.centerLeft,
                    child: Row(
                      children: <Widget>[
                        Icon(Icons.sort_by_alpha_outlined),
                        SizedBox(width: 10),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              Text(encoding.values.elementAt(index) ?? ''),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  Divider(),
                ],
              ),
            );
          }),
    );
  }

}