story_view 0.16.5 story_view: ^0.16.5 copied to clipboard
Display stories just like Whatsapp & Instagram. Can be used inline/inside ListView or Column just like Google News app. Comes with gestures to pause, forward & go to previous page.
import 'package:flutter/material.dart';
import 'package:story_view/story_view.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.green,
),
home: Home());
}
}
class Home extends StatelessWidget {
final StoryController controller = StoryController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Delicious Ghanaian Meals"),
),
body: Container(
margin: EdgeInsets.all(
8,
),
child: ListView(
children: <Widget>[
Container(
height: 300,
child: StoryView(
controller: controller,
storyItems: [
StoryItem.text(
title:
"Hello world!\nHave a look at some great Ghanaian delicacies. I'm sorry if your mouth waters. \n\nTap!",
backgroundColor: Colors.orange,
roundedTop: true,
),
// StoryItem.inlineImage(
// NetworkImage(
// "https://image.ibb.co/gCZFbx/Banku-and-tilapia.jpg"),
// caption: Text(
// "Banku & Tilapia. The food to keep you charged whole day.\n#1 Local food.",
// style: TextStyle(
// color: Colors.white,
// backgroundColor: Colors.black54,
// fontSize: 17,
// ),
// ),
// ),
StoryItem.inlineImage(
url:
"https://image.ibb.co/cU4WGx/Omotuo-Groundnut-Soup-braperucci-com-1.jpg",
controller: controller,
caption: Text(
"Omotuo & Nkatekwan; You will love this meal if taken as supper.",
style: TextStyle(
color: Colors.white,
backgroundColor: Colors.black54,
fontSize: 17,
),
),
),
StoryItem.inlineImage(
url:
"https://media.giphy.com/media/5GoVLqeAOo6PK/giphy.gif",
controller: controller,
caption: Text(
"Hektas, sektas and skatad",
style: TextStyle(
color: Colors.white,
backgroundColor: Colors.black54,
fontSize: 17,
),
),
)
],
onStoryShow: (storyItem, index) {
print("Showing a story");
},
onComplete: () {
print("Completed a cycle");
},
progressPosition: ProgressPosition.bottom,
repeat: false,
inline: true,
),
),
Material(
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => MoreStories()));
},
child: Container(
decoration: BoxDecoration(
color: Colors.black54,
borderRadius:
BorderRadius.vertical(bottom: Radius.circular(8))),
padding: EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.arrow_forward,
color: Colors.white,
),
SizedBox(
width: 16,
),
Text(
"View more stories",
style: TextStyle(fontSize: 16, color: Colors.white),
),
],
),
),
),
),
],
),
),
);
}
}
class MoreStories extends StatefulWidget {
@override
_MoreStoriesState createState() => _MoreStoriesState();
}
class _MoreStoriesState extends State<MoreStories> {
final storyController = StoryController();
@override
void dispose() {
storyController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("More"),
),
body: StoryView(
storyItems: [
StoryItem.text(
title: "I guess you'd love to see more of our food. That's great.",
backgroundColor: Colors.blue,
),
StoryItem.text(
title: "Nice!\n\nTap to continue.",
backgroundColor: Colors.red,
textStyle: TextStyle(
fontFamily: 'Dancing',
fontSize: 40,
),
),
StoryItem.pageImage(
url:
"https://image.ibb.co/cU4WGx/Omotuo-Groundnut-Soup-braperucci-com-1.jpg",
caption: Text(
"Still sampling",
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
),
controller: storyController,
),
StoryItem.pageImage(
url: "https://media.giphy.com/media/5GoVLqeAOo6PK/giphy.gif",
caption: Text(
"Working with gifs",
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
),
controller: storyController),
StoryItem.pageImage(
url: "https://media.giphy.com/media/XcA8krYsrEAYXKf4UQ/giphy.gif",
caption: Text(
"Hello, from the other side",
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
),
controller: storyController,
),
StoryItem.pageImage(
url: "https://media.giphy.com/media/XcA8krYsrEAYXKf4UQ/giphy.gif",
caption: Text(
"Hello, from the other side2",
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
),
controller: storyController,
),
],
onStoryShow: (storyItem, index) {
print("Showing a story");
},
onComplete: () {
print("Completed a cycle");
},
progressPosition: ProgressPosition.top,
repeat: false,
controller: storyController,
),
);
}
}