diff --git a/lib/main.dart b/lib/main.dart index edc4831..04a8e1a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -45,7 +45,6 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return const CupertinoApp( title: 'GGSIPU Notices', - theme: CupertinoThemeData(), home: HomePage(), ); } diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index f1d1b66..11d2304 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -1,11 +1,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:ip_notices/models/notice.dart'; import 'package:ip_notices/notifiers/firestore_notifier.dart'; import 'package:ip_notices/services/logger.dart'; import 'package:ip_notices/widgets/about_button.dart'; import 'package:ip_notices/widgets/notice_tile.dart'; -import 'package:ip_notices/widgets/theme_switch.dart'; import 'package:provider/provider.dart'; class HomePage extends StatefulWidget { @@ -16,7 +16,6 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - bool loading = false; ScrollController controller = ScrollController(); @override void initState() { @@ -38,110 +37,95 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { + SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( + statusBarColor: Colors.transparent, + )); return CupertinoPageScaffold( - backgroundColor: Colors.white, child: CustomScrollView( physics: const BouncingScrollPhysics(), controller: controller, slivers: [ + CupertinoSliverRefreshControl( + onRefresh: () { + context.read().initNoticeStream(); + return Future.delayed(const Duration(seconds: 1)) + ..then((_) {}); + }, + ), const CupertinoSliverNavigationBar( + brightness: Brightness.light, leading: AboutButton(), - trailing: ThemeSwitchButton(), - border: null, automaticallyImplyLeading: false, padding: EdgeInsetsDirectional.zero, + stretch: true, largeTitle: Text( 'Notices', - style: TextStyle( - color: Colors.black, - ), ), backgroundColor: Colors.transparent, ), - CupertinoSliverRefreshControl( - onRefresh: () { - context.read().initNoticeStream(); - return Future.delayed(const Duration(seconds: 1)) - ..then((_) {}); - }, - ), - SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return Material( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 5, 8), - child: Row( - children: [ - Text( - context.watch().priorityCheck - ? "Priority" - : "Latest", - style: TextStyle( - color: Colors.black.withOpacity(0.8), - fontWeight: FontWeight.w600, - fontSize: 20, - ), - ), - const Spacer(), - ClipOval( - child: Material( - elevation: 0, - color: Colors.transparent, - borderRadius: BorderRadius.circular(500), - child: IconButton( - icon: context - .watch() - .priorityCheck - ? const Icon(CupertinoIcons.star) - : const Icon(CupertinoIcons.time), - color: Colors.black.withOpacity(0.8), - onPressed: () { - context - .read() - .togglePriorityCheck(); - }, - ), - ), - ) - ], + SliverToBoxAdapter( + child: Material( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 5, 8), + child: Row( + children: [ + Text( + context.watch().priorityCheck + ? "Priority" + : "Latest", + style: const TextStyle( + fontWeight: FontWeight.w600, + fontSize: 20, + ), ), - ), - ); - }, - childCount: 1, + const Spacer(), + ClipOval( + child: Material( + elevation: 0, + color: Colors.transparent, + borderRadius: BorderRadius.circular(500), + child: IconButton( + icon: context.watch().priorityCheck + ? const Icon(CupertinoIcons.star) + : const Icon(CupertinoIcons.time), + color: Theme.of(context) + .textTheme + .bodyText1 + ?.color + ?.withOpacity(0.8), + onPressed: () { + context + .read() + .togglePriorityCheck(); + }, + ), + ), + ) + ], + ), + ), ), ), StreamBuilder>( stream: context.watch().noticesStream, builder: (BuildContext context, AsyncSnapshot> snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - loading = true; - } else { - loading = false; - } if (snapshot.hasError) { logger.e(snapshot.error); - return SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return Material( - color: Colors.transparent, - child: SizedBox( - height: MediaQuery.of(context).size.height - 200.0, - width: MediaQuery.of(context).size.width, - child: Center( - child: Icon( - CupertinoIcons.multiply_circle, - color: Colors.black, - ), - ), + return SliverToBoxAdapter( + child: Material( + color: Colors.transparent, + child: SizedBox( + height: MediaQuery.of(context).size.height * 0.8, + width: MediaQuery.of(context).size.width, + child: const Center( + child: Icon( + CupertinoIcons.multiply_circle, + color: Colors.red, ), - ); - }, - childCount: 1, + ), + ), ), ); } @@ -149,17 +133,15 @@ class _HomePageState extends State { return SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { - if (index == snapshot.data?.length) { - return SizedBox( + if (index == (snapshot.data?.length ?? 0) - 1) { + return const SizedBox( height: 100, width: 100, child: Center( - child: loading - ? CupertinoActivityIndicator( - animating: true, - radius: 14, - ) - : Container()), + child: CupertinoActivityIndicator( + animating: true, + radius: 14, + )), ); } final bool download = snapshot.data?[index].url @@ -167,22 +149,12 @@ class _HomePageState extends State { .toLowerCase() .contains(".pdf") ?? false; - if (context.watch().priorityCheck) { - if (snapshot.data?[index].priority ?? false) { - return NoticeTile( - download: download, - document: snapshot.data?[index], - ); - } - } else { - return NoticeTile( - download: download, - document: snapshot.data?[index], - ); - } - return Container(); + return NoticeTile( + download: download, + document: snapshot.data?[index], + ); }, - childCount: snapshot.data?.length ?? 0 + 1, + childCount: snapshot.data?.length ?? 0, ), ); } @@ -192,9 +164,9 @@ class _HomePageState extends State { return Material( color: Colors.transparent, child: SizedBox( - height: MediaQuery.of(context).size.height - 200.0, + height: MediaQuery.of(context).size.height * 0.8, width: MediaQuery.of(context).size.width, - child: Center( + child: const Center( child: CupertinoActivityIndicator( animating: true, radius: 20,