diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/homescreen.dart | 142 | ||||
-rw-r--r-- | lib/main.dart | 99 | ||||
-rw-r--r-- | lib/page_dashboard.dart | 12 | ||||
-rw-r--r-- | lib/page_home.dart | 12 | ||||
-rw-r--r-- | lib/page_hvac.dart | 12 | ||||
-rw-r--r-- | lib/page_media.dart | 12 | ||||
-rw-r--r-- | lib/widget_clock.dart | 74 |
7 files changed, 267 insertions, 96 deletions
diff --git a/lib/homescreen.dart b/lib/homescreen.dart new file mode 100644 index 0000000..232c184 --- /dev/null +++ b/lib/homescreen.dart @@ -0,0 +1,142 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_homescreen/page_dashboard.dart'; +import 'package:flutter_homescreen/page_home.dart'; +import 'package:flutter_homescreen/page_hvac.dart'; +import 'package:flutter_homescreen/page_media.dart'; +import 'package:flutter_homescreen/widget_clock.dart'; + +class Homescreen extends StatefulWidget { + Homescreen({Key? key, required this.title}) : super(key: key); + + final String title; + + @override + _HomescreenState createState() => _HomescreenState(); +} + +class _HomescreenState extends State<Homescreen> { + int _selectedIndex = 0; + + @override + Widget build(BuildContext context) { + var screenHeight = MediaQuery.of(context).size.height; + var iconSize = screenHeight / 5; + + return Scaffold( + body: Row( + children: <Widget>[ + Stack( + children: [ + NavigationRail( + backgroundColor: Colors.black12, + selectedIndex: _selectedIndex, + groupAlignment: -1.0, + minWidth: iconSize, + // leading widget? + // trailing widget does not expand to bottom + onDestinationSelected: (int index) { + setState(() { + _selectedIndex = index; + }); + }, + selectedIconTheme: IconTheme.of(context).copyWith( + size: iconSize, + color: Theme.of(context).accentColor, + ), + unselectedIconTheme: IconTheme.of(context).copyWith( + size: iconSize, + color: Theme.of(context).unselectedWidgetColor, + ), + labelType: NavigationRailLabelType.none, + destinations: <NavigationRailDestination>[ + NavigationRailDestination( + icon: Icon(Icons.house_outlined), + selectedIcon: Icon(Icons.house), + label: Text('Home'), + ), + NavigationRailDestination( + icon: Icon(Icons.drive_eta_outlined), + selectedIcon: Icon(Icons.drive_eta), + label: Text('Dashboard'), + ), + NavigationRailDestination( + icon: Icon(Icons.thermostat_outlined), + selectedIcon: Icon(Icons.thermostat), + label: Text('HVAC'), + ), + NavigationRailDestination( + icon: Icon(Icons.music_note_outlined), + selectedIcon: Icon(Icons.music_note), + label: Text('Media'), + ), + ], + ), + Positioned( + bottom: 0, + left: 0, + right: 0, + // This is the info widget with time, date, etc. + child: ClockWiddget(size: iconSize), + ) + ], + ), + const VerticalDivider(thickness: 1, width: 1), + // This is the main content. + Expanded( + child: Center(child: _childForIndex(_selectedIndex)), + ) + ], + ), + ); + } + + Widget _childForIndex(int selectedIndex) { + switch (selectedIndex) { + case 0: + return HomePage(); + case 1: + return DashboardPage(); + case 2: + return HVACPage(); + case 3: + return MediaPage(); + default: + return Text('Undefined'); + } + } +} + +/* +ElevatedButton( + child: const Text('Open app'), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SecondRoute()), + ); + }, + ), + +class SecondRoute extends StatelessWidget { + const SecondRoute({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Second Route"), + ), + body: Center( + child: ElevatedButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('Go back!'), + ), + ), + ); + } +} + +*/
\ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index b9bfc38..207ef3d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_homescreen/homescreen.dart'; void main() { runApp(MyApp()); @@ -9,105 +10,11 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'Flutter Homescreen', theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); - - // 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 - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State<MyHomePage> { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @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. - return Scaffold( - appBar: AppBar( - // 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: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: <Widget>[ - Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + home: Homescreen(title: 'Flutter Homescreen'), ); } } diff --git a/lib/page_dashboard.dart b/lib/page_dashboard.dart new file mode 100644 index 0000000..c0259ed --- /dev/null +++ b/lib/page_dashboard.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class DashboardPage extends StatelessWidget { + // TODO placeholder + @override + Widget build(BuildContext context) { + return Text( + 'Dashboard', + style: Theme.of(context).textTheme.headline1, + ); + } +} diff --git a/lib/page_home.dart b/lib/page_home.dart new file mode 100644 index 0000000..57b8e88 --- /dev/null +++ b/lib/page_home.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class HomePage extends StatelessWidget { + // TODO placeholder + @override + Widget build(BuildContext context) { + return Text( + 'HOME', + style: Theme.of(context).textTheme.headline1, + ); + } +} diff --git a/lib/page_hvac.dart b/lib/page_hvac.dart new file mode 100644 index 0000000..9a2904e --- /dev/null +++ b/lib/page_hvac.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class HVACPage extends StatelessWidget { + // TODO placeholder + @override + Widget build(BuildContext context) { + return Text( + 'HVAC', + style: Theme.of(context).textTheme.headline1, + ); + } +} diff --git a/lib/page_media.dart b/lib/page_media.dart new file mode 100644 index 0000000..6946598 --- /dev/null +++ b/lib/page_media.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class MediaPage extends StatelessWidget { + // TODO placeholder + @override + Widget build(BuildContext context) { + return Text( + 'Media', + style: Theme.of(context).textTheme.headline1, + ); + } +} diff --git a/lib/widget_clock.dart b/lib/widget_clock.dart new file mode 100644 index 0000000..c66a659 --- /dev/null +++ b/lib/widget_clock.dart @@ -0,0 +1,74 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class ClockWiddget extends StatefulWidget { + final double size; + + const ClockWiddget({Key? key, required this.size}) : super(key: key); + + @override + _ClockWiddgetState createState() => _ClockWiddgetState(); +} + +class _ClockWiddgetState extends State<ClockWiddget> { + late Timer _timer; + DateTime _now = DateTime.now(); + + @override + void initState() { + _now = DateTime.now(); + _timer = new Timer.periodic( + Duration(seconds: 1), + (Timer timer) { + setState(() { + _now = DateTime.now(); + }); + }, + ); + super.initState(); + } + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + height: widget.size, + padding: EdgeInsets.all(16.0), + decoration: BoxDecoration( + border: Border( + top: BorderSide( + width: 1.0, + ), + ), + ), + child: Column( + children: [ + FittedBox( + fit: BoxFit.contain, + child: Text( + DateFormat('EEEE').format(_now), + style: Theme.of(context).textTheme.headline2, + ), + ), + const Divider(thickness: 1), + FittedBox( + fit: BoxFit.contain, + child: Text( + DateFormat.jm().format(_now), + style: Theme.of(context).textTheme.headline2, + ), + ), + ], + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + ), + alignment: Alignment.center, + ); + } +} |