import 'dart:convert';
import 'dart:typed_data';

import 'package:diplomaticquarterapp/widgets/others/rounded_container.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/config/size_config.dart';

import 'package:flutter/material.dart';

class MedicineItemWidget extends StatefulWidget {
  final String label;
  final Color backgroundColor;
  final bool showBorder;
  final Color borderColor;
  final String url;

  MedicineItemWidget(
      {@required this.label,
      this.backgroundColor = Colors.white,
      this.showBorder = false,
      this.borderColor = Colors.white,
      this.url});

  @override
  _MedicineItemWidgetState createState() => _MedicineItemWidgetState();
}

class _MedicineItemWidgetState extends State<MedicineItemWidget> {
  @override
  Widget build(BuildContext context) {
    return new RoundedContainer(
      height: SizeConfig.heightMultiplier * 12.9,
      child: Padding(
        padding: const EdgeInsets.all(2.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            if (widget.url != null)
              Container(
                height: 39.0,
                width: 39.0,
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(7)),
                  child: Image.memory(
                    dataFromBase64String(widget.url),
                    height: SizeConfig.imageSizeMultiplier * 11,
                    width: SizeConfig.imageSizeMultiplier * 11,
                    fit: BoxFit.cover,
                  ),
                ),
              ),
            Expanded(
              child: Center(
                child: Padding(
                  padding: EdgeInsets.all(2.5),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Texts(
                      widget.label,
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
      backgroundColor: widget.backgroundColor,
      showBorder: widget.showBorder,
      borderColor: widget.borderColor,
      margin: 4,
      raduis: 10,
    );
  }

  Uint8List dataFromBase64String(String base64String) {
    return base64Decode(base64String);
  }
}
