import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vid_player_demo/controller/player_controller.dart';
import 'package:vid_player_demo/pages/image_test/view.dart';

class ImageTestPage extends StatefulWidget {
  const ImageTestPage({Key? key}) : super(key: key);
  @override
  _ImageTestPageState createState() => _ImageTestPageState();
}

class _ImageTestPageState extends State<ImageTestPage> {
  final imageNum = [
    200,
    200,
  ];

  final _playerStateController = Get.put(PlayerStateController());
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Image 载入测试"),
        ),
        body: Column(
          children: [
            const SizedBox(height: 24),
            ElevatedButton(
                onPressed: () => {_playerStateController.play(context)},
                child: const Text("Load Together")),
            const SizedBox(height: 24),
            SizedBox(height: 800, child: buildPlayersGrid(imageNum)),
          ],
        ));
  }

  Widget buildPlayersGrid(List<int> imageNumList) {
    return GridView.count(
      crossAxisCount: 3,
      childAspectRatio: 1,
      shrinkWrap: true,
      children: imageNumList
          .map((imageNum) =>
              ImageTestView(imageNum, viewSize: const Size(300, 100)))
          .toList(),
    );
  }

  @override
  void dispose() {
    super.dispose();
    Get.delete<PlayerStateController>();
    _playerStateController.dispose();
  }
}
