Skip to content

Commit

Permalink
reload when on top of the album list
Browse files Browse the repository at this point in the history
  • Loading branch information
apoleon33 committed Jan 6, 2024
1 parent 56bf8e1 commit 56a843e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/albumCard/display_as_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DisplayAlbumAsCard extends DisplayAlbum {
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width - 32,
height: MediaQuery.of(context).size.height / 2,
height: 425,
child: Card(
elevation: (dateIsToday(date))? 1: 0,
color: Theme.of(context).colorScheme.surfaceVariant,
Expand Down
64 changes: 42 additions & 22 deletions lib/route/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,16 @@ class _MyHomePageState extends State<MyHomePage> {

int indexPage = 0;

callBack(int index) {
setState(() {
indexPage = index;
});
}
late List<Widget> albumList;

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
void _createAlbumList() {
DateTime timeNow = DateTime.now();
List<Widget> albumCards = [
AlbumCard(date: timeNow, isCard: isCard),
AlbumCard(
date: timeNow,
isCard: isCard,
key: ValueKey(timeNow),
),
];

DateTime deadline = DateTime.parse('2023-12-31');
Expand All @@ -66,8 +59,32 @@ class _MyHomePageState extends State<MyHomePage> {
albumCards.add(AlbumCard(
date: date,
isCard: isCard,
key: ValueKey(DateTime.now()),
));
}
albumList = albumCards;
setState(() {});
}

@override
void initState() {
super.initState();
_createAlbumList();
}

callBack(int index) {
setState(() {
indexPage = index;
});
}

Future _refreshData() async {
_createAlbumList();
}

@override
Widget build(BuildContext context) {
List<Widget> albumCards = albumList;

return Scaffold(
appBar: AppBar(
Expand All @@ -92,14 +109,17 @@ class _MyHomePageState extends State<MyHomePage> {
]
: [],
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
albumCards,
[const Settings()]
][indexPage],
body: RefreshIndicator(
onRefresh: _refreshData,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
albumCards,
[const Settings()]
][indexPage],
),
),
),
bottomNavigationBar:
Expand Down

0 comments on commit 56a843e

Please sign in to comment.