lab6 - точно готова

This commit is contained in:
DyCTaTOR 2024-11-04 13:21:57 +04:00
parent 077b48175e
commit 25ebc8f7ab
3 changed files with 24 additions and 8 deletions

View File

@ -17,8 +17,11 @@ class MyApp extends StatelessWidget {
title: 'University App', title: 'University App',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.white, // Устанавливаем белый фон
),
home: ScaffoldMessenger(
child: UniversityScreen(),
), ),
home: UniversityScreen(),
); );
} }
} }
@ -59,6 +62,7 @@ class _UniversityScreenState extends State<UniversityScreen> {
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent), colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
useMaterial3: true, useMaterial3: true,
scaffoldBackgroundColor: Colors.white, // Устанавливаем белый фон
), ),
home: RepositoryProvider<PotterRepo>( home: RepositoryProvider<PotterRepo>(
lazy: true, lazy: true,
@ -66,9 +70,11 @@ class _UniversityScreenState extends State<UniversityScreen> {
child: BlocProvider<HomeBloc>( child: BlocProvider<HomeBloc>(
lazy: false, lazy: false,
create: (context) => HomeBloc(context.read<PotterRepo>()), create: (context) => HomeBloc(context.read<PotterRepo>()),
child: const MyHomePage(), child: Scaffold(
body: const MyHomePage(),
),
), ),
) ),
); );
} }
} }

View File

@ -35,7 +35,7 @@ class _MyHomePageState extends State<MyHomePage> {
} }
void _onNextPageListener(){ void _onNextPageListener(){
if(scrollController.offset > scrollController.position.maxScrollExtent) { if(scrollController.offset >= scrollController.position.maxScrollExtent) {
final bloc = context.read<HomeBloc>(); final bloc = context.read<HomeBloc>();
if(!bloc.state.isPaginationLoading) { if(!bloc.state.isPaginationLoading) {
bloc.add(HomeLoadDataEvent ( bloc.add(HomeLoadDataEvent (
@ -75,6 +75,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: RefreshIndicator( child: RefreshIndicator(
onRefresh: _onRefresh, onRefresh: _onRefresh,
child: ListView.builder( child: ListView.builder(
controller: scrollController,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: state.data?.data?.length ?? 0, itemCount: state.data?.data?.length ?? 0,
itemBuilder: (context, index) { itemBuilder: (context, index) {
@ -89,8 +90,13 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
), ),
), ),
) ),
), ),
BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) => state.isPaginationLoading
? const CircularProgressIndicator()
: const SizedBox.shrink(),
)
], ],
), ),
); );

View File

@ -18,14 +18,18 @@ class PotterRepo extends ApiInterface {
@override @override
Future<HomeData?> loadData( Future<HomeData?> loadData(
{OnErrorCallback? onError, String? q, int page = 1, int pageSize = 25}) async { {OnErrorCallback? onError,
String? q,
int page = 1,
int pageSize = 25
}) async {
try { try {
const String url = '$_baseUrl/v1/characters'; const String url = '$_baseUrl/v1/characters';
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>( final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
url, url,
queryParameters: { queryParameters: {
'filter[name_count]': q, 'filter[name_cont]': q,
'page[number]': page, 'page[number]': page,
'page[size]': pageSize, 'page[size]': pageSize,
}, },