From f93fdcba050854e9ef9d967da30a631d0a9044bb Mon Sep 17 00:00:00 2001 From: apoleon33 Date: Thu, 4 Jan 2024 14:52:12 +0100 Subject: [PATCH] exported `home` into a separate file --- lib/home.dart | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/main.dart | 102 +------------------------------------------------- 2 files changed, 102 insertions(+), 100 deletions(-) create mode 100644 lib/home.dart diff --git a/lib/home.dart b/lib/home.dart new file mode 100644 index 0000000..5d8e1f4 --- /dev/null +++ b/lib/home.dart @@ -0,0 +1,100 @@ +import 'package:flutter/material.dart'; + +import 'albumCard/albumCard.dart'; + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + // This widget is the home page of your application. It is stateful, meaning + // that it has a State object (defined below) that contains fields that affect + // how it looks. + + // This class is the configuration for the state. It holds the values (in this + // case the title) provided by the parent (in this case the App widget) and + // used by the build method of the State. Fields in a Widget subclass are + // always marked "final". + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + bool isCard = true; + + @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. + DateTime timeNow = DateTime.now(); + List albumCards = [ + const SizedBox(height: 16), + AlbumCard(date: timeNow, isCard: isCard), + ]; + + DateTime deadline = DateTime.parse('2023-12-31'); + + // formatting so that it looks like 'year-month-day' + String formattedDate = '${timeNow.year}-'; + if (timeNow.month < 10) { + formattedDate += '0'; + } + formattedDate += '${timeNow.month}-'; + if (timeNow.day < 10) { + formattedDate += '0'; + } + formattedDate += '${timeNow.day}'; + + DateTime date = DateTime.parse(formattedDate); + + while (date.isAfter(deadline)) { + date = DateTime(date.year, date.month, date.day - 1); + albumCards.add(const SizedBox(height: 13)); + albumCards.add(AlbumCard( + date: date, + isCard: isCard, + )); + } + + return Scaffold( + appBar: AppBar( + // TRY THIS: Try changing the color here to a specific color (to + // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar + // change color while the other colors stay the same. + backgroundColor: Theme.of(context).colorScheme.surface, + // Here we take the value from the MyHomePage object that was created by + // the App.build method, and use it to set our appbar title. + title: Align( + alignment: Alignment.centerLeft, + child: Text( + widget.title, + style: const TextStyle(fontFamily: 'Cloister', fontSize: 24.0), + )), + + actions: [ + IconButton( + onPressed: () { + setState(() { + isCard = !isCard; + }); + }, + icon: (!isCard) + ? const Icon(Icons.view_list) + : const Icon(Icons.grid_view)) + ], + ), + body: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: albumCards, + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index a25f45f..01e8ce7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,8 @@ import 'package:cradle/albumCard/albumCard.dart'; import 'package:cradle/theme_manager.dart'; import 'package:flutter/material.dart'; +import 'home.dart'; + void main() async { runApp(const MyApp()); } @@ -18,103 +20,3 @@ class MyApp extends StatelessWidget { ); } } - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - bool isCard = true; - - @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. - DateTime timeNow = DateTime.now(); - List albumCards = [ - const SizedBox(height: 16), - AlbumCard(date: timeNow, isCard: isCard), - ]; - - DateTime deadline = DateTime.parse('2023-12-31'); - - // formatting so that it looks like 'year-month-day' - String formattedDate = '${timeNow.year}-'; - if (timeNow.month < 10) { - formattedDate += '0'; - } - formattedDate += '${timeNow.month}-'; - if (timeNow.day < 10) { - formattedDate += '0'; - } - formattedDate += '${timeNow.day}'; - - DateTime date = DateTime.parse(formattedDate); - - while (date.isAfter(deadline)) { - date = DateTime(date.year, date.month, date.day - 1); - albumCards.add(const SizedBox(height: 13)); - albumCards.add(AlbumCard( - date: date, - isCard: isCard, - )); - } - - return Scaffold( - appBar: AppBar( - leading: IconButton( - icon: const Icon(Icons.menu), - onPressed: () {}, - ), - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.surface, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Center( - child: Text( - widget.title, - style: const TextStyle(fontFamily: 'Cloister'), - )), - - actions: [ - IconButton( - onPressed: () { - setState(() { - isCard = !isCard; - }); - }, - icon: (!isCard) - ? const Icon(Icons.view_list) - : const Icon(Icons.grid_view)) - ], - ), - body: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: albumCards, - ), - ), - ); - } -}