-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,310 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:story_view/story_view.dart'; | ||
|
||
class StoryViewPage extends StatefulWidget { | ||
const StoryViewPage({ | ||
super.key, | ||
required this.organization, | ||
required this.stories, | ||
}); | ||
|
||
final Organization organization; | ||
final List<Story> stories; | ||
|
||
@override | ||
State<StoryViewPage> createState() => _StoryViewPageState(); | ||
} | ||
|
||
class _StoryViewPageState extends State<StoryViewPage> { | ||
final StoryController _storyController = StoryController(); | ||
|
||
List<StoryItem> buildStoryItems(List<Story> stories) { | ||
List<StoryItem> storyItems = []; | ||
for (final story in stories) { | ||
switch (story.fileType) { | ||
case "image": | ||
storyItems.add( | ||
StoryItem.pageImage( | ||
url: "${ChirpService.urlPrefix}${story.media}", | ||
controller: _storyController, | ||
caption: Text( | ||
story.description, | ||
style: Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: Colors.white, | ||
), | ||
), | ||
loadingWidget: const CircularProgressIndicator.adaptive(), | ||
), | ||
); | ||
|
||
break; | ||
case "video": | ||
storyItems.add( | ||
StoryItem.pageVideo( | ||
"${ChirpService.urlPrefix}${story.media}", | ||
controller: _storyController, | ||
caption: Text( | ||
story.description, | ||
style: Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: Colors.white, | ||
), | ||
), | ||
loadingWidget: const CircularProgressIndicator.adaptive(), | ||
), | ||
); | ||
break; | ||
|
||
case "text": | ||
storyItems.add( | ||
StoryItem.text( | ||
title: story.description, | ||
backgroundColor: | ||
Theme.of(context).colorScheme.tertiaryContainer), | ||
); | ||
break; | ||
|
||
default: | ||
} | ||
} | ||
|
||
return storyItems; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
extendBodyBehindAppBar: true, | ||
appBar: AppBar( | ||
backgroundColor: Colors.transparent, | ||
title: Row( | ||
children: [ | ||
CircleAvatar( | ||
backgroundImage: CachedNetworkImageProvider( | ||
widget.organization.logo!, | ||
), | ||
), | ||
const SizedBox(width: 8), | ||
Text( | ||
widget.organization.name, | ||
style: Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: Colors.white, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
body: StoryView( | ||
repeat: false, | ||
onComplete: () { | ||
Navigator.pop(context); | ||
}, | ||
indicatorColor: Theme.of(context).colorScheme.secondaryContainer, | ||
indicatorForegroundColor: Theme.of(context).primaryColor, | ||
storyItems: buildStoryItems(widget.stories), | ||
controller: _storyController, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,87 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:academia/tools/chirp/pages/story_view_page.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class PersistentStorySliverDelegate extends SliverPersistentHeaderDelegate { | ||
PersistentStorySliverDelegate({ | ||
required this.child, | ||
this.numberofStories = 5, | ||
}); | ||
final Widget child; | ||
int numberofStories; | ||
@override | ||
Widget build( | ||
BuildContext context, double shrinkOffset, bool overlapsContent) { | ||
return Container( | ||
width: MediaQuery.of(context).size.width, | ||
padding: const EdgeInsets.symmetric(horizontal: 4), | ||
child: ListView.separated( | ||
itemBuilder: (context, index) { | ||
return const CircleAvatar( | ||
radius: 45, | ||
); | ||
}, | ||
itemCount: numberofStories, | ||
separatorBuilder: (context, index) => const SizedBox(width: 4), | ||
scrollDirection: Axis.horizontal, | ||
), | ||
); | ||
} | ||
class StoryHeader extends StatelessWidget { | ||
const StoryHeader({super.key}); | ||
|
||
@override | ||
double get maxExtent => 120.0; // Height of the header | ||
Widget build(BuildContext context) { | ||
final OrganizationController organizationController = | ||
Get.find<OrganizationController>(); | ||
final UserController userController = Get.find<UserController>(); | ||
|
||
@override | ||
double get minExtent => 100.0; // Height of the header when scrolled | ||
return SizedBox( | ||
height: 100, | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 8), | ||
child: FutureBuilder( | ||
future: | ||
organizationController.fetchStories(userController.authHeaders), | ||
builder: (context, snapshot) { | ||
if (snapshot.connectionState != ConnectionState.done) { | ||
return ListView.builder( | ||
shrinkWrap: true, | ||
scrollDirection: Axis.horizontal, | ||
itemBuilder: (context, index) => const CircleAvatar(radius: 35), | ||
); | ||
} | ||
|
||
@override | ||
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) { | ||
return oldDelegate != this; | ||
return Obx( | ||
() => ListView.separated( | ||
scrollDirection: Axis.horizontal, | ||
itemCount: organizationController.stories.keys.length, | ||
separatorBuilder: (context, index) => const SizedBox(width: 4), | ||
itemBuilder: (context, index) { | ||
final data = | ||
organizationController.stories.keys.elementAt(index); | ||
return Visibility( | ||
visible: organizationController.stories.values | ||
.elementAt(index) | ||
.isNotEmpty, | ||
child: GestureDetector( | ||
onTap: () { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => StoryViewPage( | ||
organization: data, | ||
stories: organizationController.stories.values | ||
.elementAt(index), | ||
), | ||
), | ||
); | ||
}, | ||
child: Column( | ||
children: [ | ||
Badge( | ||
backgroundColor: Colors.blue, | ||
label: Text( | ||
organizationController.stories.values | ||
.elementAt(index) | ||
.length | ||
.toString(), | ||
), | ||
child: CircleAvatar( | ||
radius: 35, | ||
backgroundImage: | ||
CachedNetworkImageProvider(data.logo!), | ||
), | ||
), | ||
Text( | ||
data.name, | ||
style: Theme.of(context).textTheme.bodySmall, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.