-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathlist_paged_app.dart
47 lines (44 loc) · 1.56 KB
/
list_paged_app.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'package:example/src/common/error_message.dart';
import 'package:example/src/common/loading_indicator.dart';
import 'package:example/src/post/model/post.dart';
import 'package:example/src/post/model/post_repository.dart';
import 'package:example/src/post/ui/posts_list_empty.dart';
import 'package:example/src/post/ui/posts_list_paged.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_patterns/paged_list.dart';
import 'package:flutter_bloc_patterns/view.dart';
void main() => runApp(PagedListSampleApp());
class PagedListSampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Paged List Sample App',
theme: ThemeData(primarySwatch: Colors.green),
home: BlocProvider(
create: (_) {
return PagedListBloc<Post>(PagedPostRepository())
..loadFirstPage(pageSize: 20);
},
child: _PostsPage(),
),
);
}
}
class _PostsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Posts')),
body: ViewStateBuilder<PagedList<Post>, PagedListBloc<Post>>(
loading: (context) => const LoadingIndicator(),
data: (context, page) => PostsListPaged(
page,
onLoadNextPage: context.read<PagedListBloc<Post>>().loadNextPage,
),
empty: (context) => const PostsListEmpty(),
error: (context, error) => ErrorMessage(error: error),
),
);
}
}