import 'dart:io'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/upload_online_resources_container.dart'; import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Components/upload_image_container.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; class ResourceTab extends StatefulWidget { final ResourceDetailDTO resourceDetailDTO; final Function onFileUpload; const ResourceTab({ Key key, this.resourceDetailDTO, this.onFileUpload, }) : super(key: key); @override _ResourceTabState createState() => _ResourceTabState(); } class _ResourceTabState extends State with SingleTickerProviderStateMixin { TabController _tabController; List tabsToShow = new List(); @override void initState() { tabsToShow.add(new Tab(text: "Image local")); tabsToShow.add(new Tab(text: "Image en ligne")); tabsToShow.add(new Tab(text: "Vidéo en ligne")); _tabController = new TabController(length: 3, vsync: this); _tabController.addListener(_handleTabSelection); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ TabBar( unselectedLabelColor: Colors.black, labelColor: kPrimaryColor, tabs: tabsToShow, controller: _tabController, indicatorSize: TabBarIndicatorSize.tab, indicatorColor: kPrimaryColor, ), Expanded( child: TabBarView( children: getContent(widget.resourceDetailDTO, widget.onFileUpload), controller: _tabController, ), ), ], ), ), ); } void _handleTabSelection() { print("_handleTabSelection"); print(_tabController.index); switch(_tabController.index) { case 0: setState(() { widget.resourceDetailDTO.data = null; widget.resourceDetailDTO.type = ResourceType.image; }); break; case 1: setState(() { widget.resourceDetailDTO.data = null; widget.resourceDetailDTO.type = ResourceType.imageUrl; }); break; case 2: setState(() { widget.resourceDetailDTO.data = null; widget.resourceDetailDTO.type = ResourceType.videoUrl; }); break; } } } getContent(ResourceDetailDTO resourceDetailDTO, Function onFileUpload) { List tabsToShow = new List(); print("getContent"); print(resourceDetailDTO); // Local Image tabsToShow.add( new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadImageContainer( onChanged: (File file) { print("ONCHANGED image"); print(file.path); //fileToSend = file; onFileUpload(file); resourceDetailDTO.type = ResourceType.image; } ), ) ); // Online Image tabsToShow.add( new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadOnlineResourceContainer( resourceDetailDTO: resourceDetailDTO, onChanged: (ResourceDetailDTO value) { resourceDetailDTO = value; }, ), ) ); // Online Video tabsToShow.add( new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadOnlineResourceContainer( resourceDetailDTO: resourceDetailDTO, onChanged: (ResourceDetailDTO value) { print("ONcHanged UploadOnlineResourceContainer parent"); resourceDetailDTO = value; }, ), ) ); return tabsToShow; }