|
|
@ -6,7 +6,6 @@ import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
import 'package:justmusic/main.dart';
|
|
|
|
import 'package:justmusic/main.dart';
|
|
|
|
import 'package:justmusic/main.dart';
|
|
|
|
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import '../components/post_component.dart';
|
|
|
|
import '../components/post_component.dart';
|
|
|
|
import '../components/top_nav_bar_component.dart';
|
|
|
|
import '../components/top_nav_bar_component.dart';
|
|
|
@ -28,15 +27,18 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
Timer? timer;
|
|
|
|
Timer? timer;
|
|
|
|
|
|
|
|
|
|
|
|
late List<Post> discoveryFeed;
|
|
|
|
late List<Post> discoveryFeed;
|
|
|
|
late List<Post> displayFeed;
|
|
|
|
late Tuple2<List<Post>, List<Post>> displayFeed;
|
|
|
|
bool isDismissed = true;
|
|
|
|
bool isDismissed = true;
|
|
|
|
bool choiceFeed = false;
|
|
|
|
bool choiceFeed = true;
|
|
|
|
|
|
|
|
PageController controller = PageController();
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
friendFeed = MyApp.postViewModel.postsFriends;
|
|
|
|
friendFeed = MyApp.postViewModel.postsFriends;
|
|
|
|
discoveryFeed = MyApp.postViewModel.bestPosts;
|
|
|
|
discoveryFeed = MyApp.postViewModel.bestPosts;
|
|
|
|
|
|
|
|
displayFeed =
|
|
|
|
|
|
|
|
Tuple2(MyApp.postViewModel.postsFriends.reversed.toList(), MyApp.postViewModel.bestPosts.reversed.toList());
|
|
|
|
animationController = AnimationController(
|
|
|
|
animationController = AnimationController(
|
|
|
|
vsync: this,
|
|
|
|
vsync: this,
|
|
|
|
duration: Duration(milliseconds: 400),
|
|
|
|
duration: Duration(milliseconds: 400),
|
|
|
@ -46,38 +48,36 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
curve: Curves.easeInOutSine,
|
|
|
|
curve: Curves.easeInOutSine,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
animationController.forward();
|
|
|
|
animationController.forward();
|
|
|
|
|
|
|
|
_fetchData().then((tuple) {
|
|
|
|
|
|
|
|
friendFeed = tuple.item2;
|
|
|
|
|
|
|
|
displayFeed = tuple.item1;
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future _refresh() async {
|
|
|
|
@override
|
|
|
|
if (choiceFeed) {
|
|
|
|
void dispose() {
|
|
|
|
await MyApp.postViewModel.getBestPosts();
|
|
|
|
animationController.dispose();
|
|
|
|
setState(() {});
|
|
|
|
super.dispose();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
await MyApp.postViewModel.getPostsFriends();
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _refresh() async {
|
|
|
|
|
|
|
|
Tuple2<List<Post>, List<Post>> tuple = await _fetchData();
|
|
|
|
|
|
|
|
displayFeed = Tuple2(tuple.item1, tuple.item2);
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void changeFeed(bool choice) {
|
|
|
|
void changeFeed(bool choice) {
|
|
|
|
// Mettez ici le code pour l'action que vous souhaitez effectuer avec le paramètre
|
|
|
|
|
|
|
|
if (choice) {
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
animationController.reset();
|
|
|
|
if (choice) {
|
|
|
|
displayFeed = MyApp.postViewModel.postsFriends.reversed.toList();
|
|
|
|
controller.nextPage(duration: Duration(milliseconds: 300), curve: Curves.linear);
|
|
|
|
animationController.forward();
|
|
|
|
|
|
|
|
choiceFeed = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
controller.previousPage(duration: Duration(milliseconds: 300), curve: Curves.linear);
|
|
|
|
animationController.reset();
|
|
|
|
|
|
|
|
displayFeed = MyApp.postViewModel.bestPosts.reversed.toList();
|
|
|
|
|
|
|
|
animationController.forward();
|
|
|
|
|
|
|
|
choiceFeed = true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void openDetailPost(int index) {
|
|
|
|
void openDetailPost(Post post) {
|
|
|
|
showModalBottomSheet(
|
|
|
|
showModalBottomSheet(
|
|
|
|
backgroundColor: bgModal,
|
|
|
|
backgroundColor: bgModal,
|
|
|
|
elevation: 1,
|
|
|
|
elevation: 1,
|
|
|
@ -91,7 +91,7 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
builder: ((BuildContext context) {
|
|
|
|
builder: ((BuildContext context) {
|
|
|
|
return ClipRRect(
|
|
|
|
return ClipRRect(
|
|
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
|
|
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
|
|
|
|
child: DetailPostScreen(post: displayFeed[index]));
|
|
|
|
child: DetailPostScreen(post: post));
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -99,32 +99,43 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
_fetchData() async {
|
|
|
|
_fetchData() async {
|
|
|
|
friendFeed = await MyApp.postViewModel.getPostsFriends();
|
|
|
|
friendFeed = await MyApp.postViewModel.getPostsFriends();
|
|
|
|
discoveryFeed = await MyApp.postViewModel.getBestPosts();
|
|
|
|
discoveryFeed = await MyApp.postViewModel.getBestPosts();
|
|
|
|
return Tuple2(friendFeed, displayFeed);
|
|
|
|
return Tuple2(friendFeed, discoveryFeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
switchTopBar(int index) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (index == 0) {
|
|
|
|
if (choiceFeed) {
|
|
|
|
setState(() {
|
|
|
|
displayFeed = MyApp.postViewModel.postsFriends.reversed.toList();
|
|
|
|
choiceFeed = true;
|
|
|
|
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
displayFeed = MyApp.postViewModel.bestPosts.reversed.toList();
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
choiceFeed = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_fetchData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
bool empty =
|
|
|
|
|
|
|
|
(choiceFeed == true && displayFeed.item1.isEmpty) || (choiceFeed == false && displayFeed.item2.isEmpty);
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
resizeToAvoidBottomInset: true,
|
|
|
|
resizeToAvoidBottomInset: true,
|
|
|
|
backgroundColor: bgColor,
|
|
|
|
backgroundColor: bgColor,
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
body: displayFeed.isEmpty
|
|
|
|
body: Container(
|
|
|
|
? Container(
|
|
|
|
|
|
|
|
width: double.infinity,
|
|
|
|
width: double.infinity,
|
|
|
|
|
|
|
|
height: double.infinity,
|
|
|
|
child: Stack(
|
|
|
|
child: Stack(
|
|
|
|
fit: StackFit.expand,
|
|
|
|
fit: StackFit.expand,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
AnimatedOpacity(
|
|
|
|
|
|
|
|
opacity: empty ? 1 : 0,
|
|
|
|
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
|
|
|
|
curve: Curves.easeIn,
|
|
|
|
|
|
|
|
child: Container(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image:
|
|
|
|
image: AssetImage("assets/images/empty_bg.png"), fit: BoxFit.cover, opacity: 0.3),
|
|
|
|
DecorationImage(image: AssetImage("assets/images/empty_bg.png"), fit: BoxFit.cover, opacity: 0.3),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(top: 140.h, left: defaultPadding),
|
|
|
|
padding: EdgeInsets.only(top: 140.h, left: defaultPadding),
|
|
|
@ -138,82 +149,77 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
PageView(
|
|
|
|
|
|
|
|
onPageChanged: (value) {
|
|
|
|
|
|
|
|
switchTopBar(value);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
controller: controller,
|
|
|
|
|
|
|
|
scrollBehavior: const ScrollBehavior().copyWith(overscroll: false),
|
|
|
|
|
|
|
|
physics: AlwaysScrollableScrollPhysics(),
|
|
|
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
Align(
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: IgnorePointer(
|
|
|
|
child: CircularRevealAnimation(
|
|
|
|
|
|
|
|
animation: animation,
|
|
|
|
|
|
|
|
centerOffset: Offset(30.w, -100),
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
height: 240.h,
|
|
|
|
height: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
constraints: BoxConstraints(maxWidth: 600),
|
|
|
|
gradient: LinearGradient(
|
|
|
|
padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0),
|
|
|
|
begin: Alignment.topRight,
|
|
|
|
child: RefreshIndicator(
|
|
|
|
stops: [0.3, 1],
|
|
|
|
displacement: 20,
|
|
|
|
colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])),
|
|
|
|
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
|
|
|
),
|
|
|
|
onRefresh: _refresh,
|
|
|
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
|
|
|
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
|
|
|
|
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
|
|
|
|
shrinkWrap: false,
|
|
|
|
|
|
|
|
itemCount: displayFeed.item1.length,
|
|
|
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 40),
|
|
|
|
|
|
|
|
child:
|
|
|
|
|
|
|
|
PostComponent(callback: openDetailPost, post: displayFeed.item1[index], index: index),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Align(
|
|
|
|
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
|
|
|
|
child: ConstrainedBox(
|
|
|
|
|
|
|
|
constraints: BoxConstraints(maxWidth: 800),
|
|
|
|
|
|
|
|
child: TopNavBarComponent(callback: changeFeed),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
Align(
|
|
|
|
: Container(
|
|
|
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
|
|
|
child: Stack(
|
|
|
|
|
|
|
|
fit: StackFit.expand,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
|
|
child: Align(
|
|
|
|
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: CircularRevealAnimation(
|
|
|
|
child: CircularRevealAnimation(
|
|
|
|
animation: animation,
|
|
|
|
animation: animation,
|
|
|
|
centerOffset: Offset(30.w, -100),
|
|
|
|
centerOffset: Offset(30.w, -100),
|
|
|
|
child: Expanded(
|
|
|
|
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
height: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
constraints: BoxConstraints(maxWidth: 600),
|
|
|
|
constraints: BoxConstraints(maxWidth: 600),
|
|
|
|
padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0),
|
|
|
|
padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0),
|
|
|
|
child: Expanded(
|
|
|
|
child: RefreshIndicator(
|
|
|
|
child: FutureBuilder(
|
|
|
|
|
|
|
|
future: _fetchData(),
|
|
|
|
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
|
|
|
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
|
|
|
return RefreshIndicator(
|
|
|
|
|
|
|
|
displacement: 20,
|
|
|
|
displacement: 20,
|
|
|
|
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
|
|
|
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
|
|
|
onRefresh: _refresh,
|
|
|
|
onRefresh: _refresh,
|
|
|
|
child: Expanded(
|
|
|
|
|
|
|
|
child: ListView.builder(
|
|
|
|
child: ListView.builder(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
shrinkWrap: true,
|
|
|
|
shrinkWrap: false,
|
|
|
|
itemCount: displayFeed.length,
|
|
|
|
itemCount: displayFeed.item2.length,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
return Padding(
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 40),
|
|
|
|
padding: const EdgeInsets.only(bottom: 40),
|
|
|
|
child: PostComponent(
|
|
|
|
child:
|
|
|
|
callback: openDetailPost, post: displayFeed[index], index: index),
|
|
|
|
PostComponent(callback: openDetailPost, post: displayFeed.item2[index], index: index),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Center(
|
|
|
|
|
|
|
|
child: CupertinoActivityIndicator(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Align(
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
@ -232,11 +238,39 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: ConstrainedBox(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(maxWidth: 800),
|
|
|
|
constraints: BoxConstraints(maxWidth: 800),
|
|
|
|
child: TopNavBarComponent(callback: changeFeed),
|
|
|
|
child: TopNavBarComponent(callback: changeFeed, choice: choiceFeed),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NoEdgeEffectScrollPhysics extends ScrollPhysics {
|
|
|
|
|
|
|
|
const NoEdgeEffectScrollPhysics({ScrollPhysics? parent}) : super(parent: parent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
NoEdgeEffectScrollPhysics applyTo(ScrollPhysics? ancestor) {
|
|
|
|
|
|
|
|
return NoEdgeEffectScrollPhysics(parent: buildParent(ancestor));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
double applyBoundaryConditions(ScrollMetrics position, double value) {
|
|
|
|
|
|
|
|
// Supprimez l'effet de bord (effet de vague)
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
double applyPhysicsToUserOffset(ScrollMetrics position, double offset) {
|
|
|
|
|
|
|
|
// Supprimez la rétroaction haptique
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Simulation? createBallisticSimulation(ScrollMetrics position, double velocity) {
|
|
|
|
|
|
|
|
// Désactivez l'overscroll
|
|
|
|
|
|
|
|
return super.createBallisticSimulation(position, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|