callback info #29

Merged
emre.kartal merged 1 commits from CALLBACK_IMAGE into master 2 years ago

@ -20,7 +20,16 @@ import 'buttonPostComponent.dart';
class EditablePostComponent extends StatefulWidget { class EditablePostComponent extends StatefulWidget {
final Music? music; final Music? music;
const EditablePostComponent({Key? key, this.music}) : super(key: key); final Function callBackImage;
final Function callBackCity;
final Function callBackDescription;
const EditablePostComponent(
{Key? key,
this.music,
required this.callBackImage,
required this.callBackCity,
required this.callBackDescription})
: super(key: key);
@override @override
State<EditablePostComponent> createState() => _EditablePostComponentState(); State<EditablePostComponent> createState() => _EditablePostComponentState();
@ -60,16 +69,24 @@ class _EditablePostComponentState extends State<EditablePostComponent>
final imageTemp = File(image.path); final imageTemp = File(image.path);
setState(() { setState(() {
this.image = imageTemp; this.image = imageTemp;
widget.callBackImage(imageTemp);
}); });
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
} }
void _updateDescription(String text) {
setState(() {
widget.callBackDescription(text);
});
}
void _selectLocation(Tuple2<String, String> location) { void _selectLocation(Tuple2<String, String> location) {
Navigator.pop(context); Navigator.pop(context);
setState(() { setState(() {
selectedCity = location; selectedCity = location;
widget.callBackCity(location);
}); });
} }
@ -96,6 +113,13 @@ class _EditablePostComponentState extends State<EditablePostComponent>
); );
} }
@override
void dispose() {
_controller.dispose();
animationController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ClipRRect( return ClipRRect(
@ -276,6 +300,9 @@ class _EditablePostComponentState extends State<EditablePostComponent>
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
child: TextFormField( child: TextFormField(
onChanged: (value) {
_updateDescription(value);
},
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
minLines: 1, minLines: 1,
cursorColor: primaryColor, cursorColor: primaryColor,

@ -5,7 +5,10 @@ import 'package:google_fonts/google_fonts.dart';
class PostButtonComponent extends StatefulWidget { class PostButtonComponent extends StatefulWidget {
final bool empty; final bool empty;
const PostButtonComponent({Key? key, required this.empty}) : super(key: key); final Function callback;
const PostButtonComponent(
{Key? key, required this.empty, required this.callback})
: super(key: key);
@override @override
State<PostButtonComponent> createState() => _PostButtonComponentState(); State<PostButtonComponent> createState() => _PostButtonComponentState();
@ -67,12 +70,17 @@ class _PostButtonComponentState extends State<PostButtonComponent>
), ),
); );
} }
return Container( return GestureDetector(
onTap: () {
widget.callback();
},
child: Container(
width: double.infinity, width: double.infinity,
height: 90, height: 90,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.transparent, borderRadius: BorderRadius.circular(1000)), color: Colors.transparent,
borderRadius: BorderRadius.circular(1000)),
child: Stack( child: Stack(
children: [ children: [
AnimatedBuilder( AnimatedBuilder(
@ -80,7 +88,8 @@ class _PostButtonComponentState extends State<PostButtonComponent>
builder: (context, child) { builder: (context, child) {
return Transform.translate( return Transform.translate(
offset: Offset( offset: Offset(
_controller.value * (MediaQuery.of(context).size.width - 200), _controller.value *
(MediaQuery.of(context).size.width - 200),
0, 0,
), ),
child: child, child: child,
@ -148,6 +157,7 @@ class _PostButtonComponentState extends State<PostButtonComponent>
) )
], ],
), ),
),
); );
} }
} }

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/Material.dart'; import 'package:flutter/Material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -22,7 +23,15 @@ class _PostScreenState extends State<PostScreen>
late AnimationController _controller; late AnimationController _controller;
Music? selectedMusic; Music? selectedMusic;
File? selectedImage;
Tuple2<String, String>? selectedCity; Tuple2<String, String>? selectedCity;
String? description;
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override @override
void initState() { void initState() {
@ -41,6 +50,24 @@ class _PostScreenState extends State<PostScreen>
}); });
} }
void _selectImage(File image) {
setState(() {
selectedImage = image;
});
}
void _descritpion(String text) {
setState(() {
description = text;
});
}
void _selectLocation(Tuple2<String, String> location) {
setState(() {
selectedCity = location;
});
}
void openSearchSong() { void openSearchSong() {
showModalBottomSheet( showModalBottomSheet(
transitionAnimationController: _controller, transitionAnimationController: _controller,
@ -64,6 +91,12 @@ class _PostScreenState extends State<PostScreen>
); );
} }
displayinfo() {
print("cc");
print(
"${selectedCity},${selectedMusic?.title},${selectedImage?.path},${description}");
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -107,11 +140,18 @@ class _PostScreenState extends State<PostScreen>
), ),
GestureDetector( GestureDetector(
onTap: openSearchSong, onTap: openSearchSong,
child: EditablePostComponent(music: selectedMusic)), child: EditablePostComponent(
music: selectedMusic,
callBackImage: _selectImage,
callBackDescription: _descritpion,
callBackCity: _selectLocation)),
SizedBox( SizedBox(
height: 40.h, height: 40.h,
), ),
PostButtonComponent(empty: selectedMusic == null), PostButtonComponent(
empty: selectedMusic == null,
callback: displayinfo,
),
SizedBox( SizedBox(
height: 40.h, height: 40.h,
), ),

Loading…
Cancel
Save