ruffde_highlights 0.0.3 ruffde_highlights: ^0.0.3 copied to clipboard
A package that is is developed and maintain by Ruffde Team and used internally
import 'package:flutter/material.dart';
import 'package:ruffde_highlights/highlight_page_views/heighlight_page_view.dart';
void main() {
runApp(MyApp());
}
class UserModel {
UserModel(this.stories, this.userName, this.imageUrl);
final List<HeightLightModel> stories;
final String userName;
final String imageUrl;
}
class HeightLightModel {
HeightLightModel(this.imageUrl);
final String imageUrl;
}
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.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: Text('show stories'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return HeighLightPage();
},
),
);
},
),
),
);
}
}
class HeighLightPage extends StatefulWidget {
HeighLightPage({Key? key}) : super(key: key);
@override
_HeighLightPageState createState() => _HeighLightPageState();
}
class _HeighLightPageState extends State<HeighLightPage> {
late ValueNotifier<IndicatorAnimationCommand> indicatorAnimationController;
final sampleUsers = [
UserModel([
HeightLightModel(
"https://images.unsplash.com/photo-1609167830240-fc81e9cfd9bf?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=668&q=80"),
HeightLightModel(
"https://images.unsplash.com/photo-1561758033-7e924f619b47?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=668&q=80"),
HeightLightModel(
"https://images.unsplash.com/photo-1621792907526-e69888069079?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80"),
HeightLightModel(
"https://images.unsplash.com/photo-1621792907789-666f0e69ea03?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80"),
], "Guta Restu",
"https://images.unsplash.com/photo-1609262772830-0decc49ec18c?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzMDF8fHxlbnwwfHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60"),
UserModel([
HeightLightModel(
"https://images.unsplash.com/photo-1621797350488-fb28c9217e3b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2734&q=80"),
], "Kumar Restu",
"https://images.unsplash.com/photo-1601758125946-6ec2ef64daf8?ixid=MXwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwzMjN8fHxlbnwwfHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60"),
UserModel([
HeightLightModel(
"https://images.unsplash.com/photo-1621792907526-e69888069079?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80"),
HeightLightModel(
"https://images.unsplash.com/photo-1621792907789-666f0e69ea03?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80"),
HeightLightModel(
"https://images.unsplash.com/photo-1505252585461-04db1eb84625?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=704&q=80"),
], "Pandeyji Restur",
"https://images.unsplash.com/photo-1609127102567-8a9a21dc27d8?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzOTh8fHxlbnwwfHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60"),
];
@override
void initState() {
super.initState();
indicatorAnimationController = ValueNotifier<IndicatorAnimationCommand>(
IndicatorAnimationCommand.resume);
}
@override
void dispose() {
indicatorAnimationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: HeightLightPageView(
itemBuilder: (context, pageIndex, storyIndex) {
final user = sampleUsers[pageIndex];
final story = user.stories[storyIndex];
return Stack(
children: [
Positioned.fill(
child: Container(color: Colors.black),
),
Positioned.fill(
child: Image.network(
story.imageUrl,
fit: BoxFit.cover,
),
),
Padding(
padding: const EdgeInsets.only(top: 44, left: 8),
child: Row(
children: [
Container(
height: 32,
width: 32,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(user.imageUrl),
fit: BoxFit.cover,
),
shape: BoxShape.circle,
),
),
const SizedBox(
width: 8,
),
Text(
user.userName,
style: TextStyle(
fontSize: 17,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
);
},
gestureItemBuilder: (context, pageIndex, storyIndex) {
return Stack(children: [
Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(top: 32),
child: IconButton(
padding: EdgeInsets.zero,
color: Colors.white,
icon: Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
},
),
),
),
if (pageIndex == 0)
Center(
child: ElevatedButton(
child: Text('show modal bottom sheet'),
onPressed: () async {
indicatorAnimationController.value =
IndicatorAnimationCommand.pause;
await showModalBottomSheet(
context: context,
builder: (context) => SizedBox(
height: MediaQuery.of(context).size.height / 2,
child: Padding(
padding: EdgeInsets.all(24),
child: Text(
'Look! The indicator is now paused\n\n'
'It will be coutinued after closing the modal bottom sheet.',
style: Theme.of(context).textTheme.headline5,
textAlign: TextAlign.center,
),
),
),
);
indicatorAnimationController.value =
IndicatorAnimationCommand.resume;
},
),
),
]);
},
indicatorAnimationController: indicatorAnimationController,
initialStoryIndex: (pageIndex) {
if (pageIndex == 0) {
return 1;
}
return 0;
},
pageLength: sampleUsers.length,
storyLength: (int pageIndex) {
return sampleUsers[pageIndex].stories.length;
},
onPageLimitReached: () {
Navigator.pop(context);
},
),
);
}
}