import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart';

class MineNavBg extends StatefulWidget {
  final Map<String, dynamic> data;

  const MineNavBg(this.data, {Key key}) : super(key: key);

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

class _MineNavBgState extends State<MineNavBg> {
  @override
  void initState() {
    super.initState();
  }

  void _updateBg() {
    final double statusBarHeight = MediaQuery.of(context).padding.top;
    if (widget.data.containsKey('img')) {
      Provider.of<MainPageBgNotifier>(context, listen: false).switchBg(
        Container(
          width: double.infinity,
          height: statusBarHeight + 250,
          child: CachedNetworkImage(
            imageUrl: widget.data['img'],
            fit: BoxFit.fitHeight,
          ),
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    Future.delayed(Duration.zero, () {
      _updateBg();
    });
    return Container();
  }
}
