130 lines
3.5 KiB
Dart
130 lines
3.5 KiB
Dart
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 ResourceDTO resourceDTO;
|
|
final Function onFileUpload;
|
|
const ResourceTab({
|
|
Key key,
|
|
this.resourceDTO,
|
|
this.onFileUpload,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_ResourceTabState createState() => _ResourceTabState();
|
|
}
|
|
|
|
class _ResourceTabState extends State<ResourceTab> with SingleTickerProviderStateMixin {
|
|
TabController _tabController;
|
|
List<Tab> tabsToShow = new List<Tab>();
|
|
|
|
@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.resourceDTO, widget.onFileUpload),
|
|
controller: _tabController,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _handleTabSelection() {
|
|
switch(_tabController.index) {
|
|
case 0:
|
|
setState(() {
|
|
widget.resourceDTO.data = null;
|
|
widget.resourceDTO.type = ResourceType.image;
|
|
});
|
|
break;
|
|
case 1:
|
|
setState(() {
|
|
widget.resourceDTO.data = null;
|
|
widget.resourceDTO.type = ResourceType.imageUrl;
|
|
});
|
|
break;
|
|
case 2:
|
|
setState(() {
|
|
widget.resourceDTO.data = null;
|
|
widget.resourceDTO.type = ResourceType.videoUrl;
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
getContent(ResourceDTO resourceDTO, Function onFileUpload) {
|
|
List<Widget> tabsToShow = new List<Widget>();
|
|
|
|
// Local Image
|
|
tabsToShow.add(
|
|
new Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
|
child: UploadImageContainer(
|
|
onChanged: (File file) {
|
|
onFileUpload(file);
|
|
resourceDTO.type = ResourceType.image;
|
|
}
|
|
),
|
|
)
|
|
);
|
|
|
|
// Online Image
|
|
tabsToShow.add(
|
|
new Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
|
child: UploadOnlineResourceContainer(
|
|
resourceDTO: resourceDTO,
|
|
onChanged: (ResourceDTO value) {
|
|
resourceDTO = value;
|
|
},
|
|
),
|
|
)
|
|
);
|
|
|
|
// Online Video
|
|
tabsToShow.add(
|
|
new Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
|
child: UploadOnlineResourceContainer(
|
|
resourceDTO: resourceDTO,
|
|
onChanged: (ResourceDTO value) {
|
|
resourceDTO = value;
|
|
},
|
|
),
|
|
)
|
|
);
|
|
return tabsToShow;
|
|
} |