Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:io';
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:font_awesome_flutter/font_awesome_flutter.dart';
- import 'package:memoapp/AppData.dart';
- import 'package:memoapp/api/api.dart';
- import 'package:memoapp/api/model.dart';
- import 'package:memoapp/components/Loading.dart';
- import 'package:memoapp/components/TermView.dart';
- import 'package:memoapp/components/AudioList.dart';
- import 'package:memoapp/components/addContentButton.dart';
- import 'package:memoapp/screen/recordaudioscreen.dart';
- //import 'package:image_picker/image_picker.dart';
- import 'package:flutter/material.dart';
- import 'package:path/path.dart' show join;
- import 'package:path_provider/path_provider.dart';
- import 'package:image_picker/image_picker.dart';
- import 'package:uuid/uuid.dart';
- import 'package:youtube_player/youtube_player.dart';
- typedef SearchCallback = void Function(String searchString);
- class TermDetail extends StatefulWidget {
- String id;
- TermDetail(this.id);
- @override
- State<StatefulWidget> createState() {
- return new TermDetailState(id);
- }
- }
- List<IconData> images = [
- Icons.looks_one,
- Icons.looks_two,
- Icons.looks_3,
- Icons.looks_4,
- ];
- List<String> title = [
- "audio",
- "visual",
- "translated_as",
- "in",
- "related",
- "def",
- "def_of",
- ];
- class TermDetailState extends State<TermDetail> {
- Widget cp = Container();
- Widget switcher = Container();
- String id;
- TermInfo term;
- int _addStatus = 1;
- TermDetailState(this.id);
- get appState {
- return appData.appState;
- }
- @override
- void initState() {
- super.initState();
- fetchData();
- }
- fetchData() async {
- var result = await fetchAudioList(id, 0, 10);
- setState(() {
- term = result;
- cp = getAudiosPage();
- switcher = Row(
- children: <Widget>[Text("1 "), Text("2")],
- mainAxisAlignment: MainAxisAlignment.center,
- );
- });
- }
- void addContent() {
- if (_addStatus == 0) {
- setState(() {
- _addStatus = 1;
- });
- } else if (_addStatus == 1) {
- setState(() {
- _addStatus = 0;
- });
- }
- }
- void openAddAudio() {
- print("audio open!");
- var route = MaterialPageRoute(
- builder: (_) => new RecordAudioScreen(
- term: term,
- ));
- Navigator.pushReplacement(context, route);
- }
- Widget getAudiosPage() {
- return term.audio.items.length > 0
- ? new AudioList(term, fetchData)
- : Align(
- child: Container(
- width: 200,
- child: Text(
- "No audios yet ;)",
- style: TextStyle(fontSize: 20, color: Colors.blue[800]),
- ),
- alignment: Alignment(0, 0),
- padding: EdgeInsets.only(top: 10, bottom: 10),
- decoration: BoxDecoration(
- color: Colors.grey[200],
- borderRadius: BorderRadius.circular(20),
- boxShadow: <BoxShadow>[BoxShadow(blurRadius: 5)]),
- ),
- );
- }
- var currentPage = images.length - 1.0;
- @override
- Widget build(BuildContext context) {
- if (term == null) {
- return Loading();
- }
- PageController controller = PageController(initialPage: images.length - 1);
- controller.addListener(() {
- setState(() {
- currentPage = controller.page;
- });
- });
- var RadialAddButton = Container(
- child: RadialMenu(
- icons: <RadialBtn>[
- RadialBtn(
- angle: 160,
- color: Colors.grey[600],
- icon: FontAwesomeIcons.cameraRetro,
- onTap: () {
- openCamera();
- }),
- RadialBtn(
- angle: 110,
- color: Colors.green,
- icon: FontAwesomeIcons.images,
- onTap: () {
- openGalery();
- }),
- RadialBtn(
- angle: 40,
- color: Colors.orange,
- icon: FontAwesomeIcons.microphoneAlt,
- onTap: () {
- openAddAudio();
- }),
- ],
- ));
- return new Scaffold(
- appBar: AppBar(
- title: Text("Detail"),
- ),
- body: ListView(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(top: 10, bottom: 10),
- child: TermView(term: term, tappable: false),
- ),
- //switcher,
- Stack(
- children: <Widget>[
- CardScrollWidget(currentPage),
- Positioned.fill(
- child: PageView.builder(
- itemCount: images.length,
- controller: controller,
- reverse: true,
- itemBuilder: (context, index) {
- return Container(child: Text(index.toString()),);
- },
- ),
- )
- ],
- ),
- cp,
- RadialAddButton,
- ],
- ),
- );
- }
- void openCamera() async {
- File cameraFile;
- print("camera open!");
- cameraFile = await ImagePicker.pickImage(
- source: ImageSource.camera,
- //maxHeight: 50.0,
- //maxWidth: 50.0,
- );
- if (cameraFile != null) {
- print("You selected camera image : " + cameraFile.path);
- uploadPhoto(cameraFile);
- } else {
- print("no data");
- }
- setState(() {});
- }
- void openGalery() async {
- File galleryFile;
- galleryFile = await ImagePicker.pickImage(
- source: ImageSource.gallery,
- // maxHeight: 50.0,
- // maxWidth: 50.0,
- );
- if (galleryFile != null) {
- print("You selected gallery image : " + galleryFile.path);
- uploadPhoto(galleryFile);
- } else {
- print("no data");
- }
- setState(() {});
- }
- void uploadPhoto(File f) async {
- List<int> bytes = f.readAsBytesSync();
- // TODO link to current term
- var uuid = new Uuid();
- final user = appData.appState.user;
- String datauid = uuid.v4();
- final remotePath = "user/${user.uid}/visual/${datauid}.jpeg";
- var res = await upload("$remotePath", 'visual/jpeg', bytes);
- TermUpdate tup = new TermUpdate();
- tup.imageUid = res.uid;
- print(tup.imageUid);
- var res2 = await upadteTerm(term.uid, tup);
- print(res2.toString());
- }
- }
- var gar = 12.0/16.0;
- //Переименовать...
- class EdgeSelectorData
- {
- String dgeName;
- Color backColor;
- }
- class CardScrollWidget extends StatelessWidget {
- var currentPage;
- var padding = 50.0;
- var verticalInset = 20.0;
- CardScrollWidget(this.currentPage);
- @override
- Widget build(BuildContext context) {
- return new AspectRatio(
- aspectRatio: gar* 2,
- child: LayoutBuilder(builder: (context, contraints) {
- var width = contraints.maxWidth;
- var height = contraints.maxHeight;
- var safeWidth = width - 2 * padding;
- var safeHeight = height - 2 * padding;
- var heightOfPrimaryCard = safeHeight;
- var widthOfPrimaryCard = heightOfPrimaryCard * gar;
- var primaryCardLeft = safeWidth - widthOfPrimaryCard;
- var horizontalInset = primaryCardLeft / 2;
- List<Widget> cardList = new List();
- for (var i = 0; i < images.length; i++) {
- var delta = i - currentPage;
- bool isOnRight = delta > 0;
- var start = padding +
- max(
- primaryCardLeft -
- horizontalInset * -delta * (isOnRight ? 15 : 0.5 ),
- 0.0);
- var cardItem = Positioned.directional(
- top: padding + verticalInset * max(-delta, 0.0),
- bottom: padding + verticalInset * max(-delta, 0.0),
- start: start-100,
- textDirection: TextDirection.rtl,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(16.0),
- child: Container(
- decoration: BoxDecoration(color: Colors.grey[i*100+100], boxShadow: [
- BoxShadow(
- color: Colors.black12,
- offset: Offset(3.0, 6.0),
- blurRadius: 20.0)
- ]),
- child: Container(
- //aspectRatio: gar,
- child: Stack(
- //fit: StackFit.expand,
- children: <Widget>[
- //Icon(images[i]),
- Align(
- alignment: Alignment.center,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.symmetric(
- horizontal: 16.0, vertical: 8.0),
- child: Text(title[i],
- style: TextStyle(
- color: Colors.black,
- fontSize: sqrt(pow(currentPage-i,2))<0.8?25-20*sqrt(pow(currentPage-i,2)):15,
- fontFamily: "SF-Pro-Text-Regular")),
- ),
- ],
- ),
- )
- ],
- ),
- ),
- ),
- ),
- );
- cardList.add(cardItem);
- }
- return Stack(
- children: cardList,
- );
- }),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement