diff --git a/lib/home.dart b/lib/home.dart new file mode 100644 index 0000000..2ad5f71 --- /dev/null +++ b/lib/home.dart @@ -0,0 +1,217 @@ +import 'package:flutter/material.dart'; + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + final String title; + + @override + State createState() => _MyHomePageState(); +} +//Da haben wir letztes mal gemacht aber ich weiß jetzt nicht warum es nicht funktioniert +//?????? +/*class _MyHomePageState extends State { + int _selectedIndex = 0; + static final List _widgetOptions = + [ + Table(border: TableBorder.all(), + columnWidths:const< + + int, TableColumnWidth>{ + 0: IntrinsicColumnWidth(), + 1: FlexColumnWidth(), + 2: FixedColumnWidth(64), + }, + defaultVerticalAlignment: TableCellVerticalAlignment.middle, + children: [ + TableRow( + children: [ + Container( + height: 32, + color: Colors.green, + ), + TableCell( + verticalAlignment: TableCellVerticalAlignment.top, + child: Container( + height: 32, + width: 32, + color: Colors.red, + ), + ), + Container( + height: 64, + color: Colors.blue, + ), + ], + ), + TableRow( + decoration: const BoxDecoration( + color: Colors.grey, + ), + children: [ + Container( + height: 64, + width: 128, + color: Colors.purple, + ), + Container( + height: 32, + color: Colors.yellow, + ), + Center( + child: Container( + height: 32, + width: 32, + color: Colors.orange, + ), + ), + ], + ), + ], + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + + return Scaffold( + appBar: AppBar( + + title: Text(widget.title), + ), + body: Center( +/* + child: Column( + + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'Knopfdruck:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], + ),*/ + child: _widgetOptions.elementAt(_selectedIndex), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + bottomNavigationBar: BottomAppBar( + color: const Color(0xFF1601FD), + child: IconTheme( + data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + IconButton( + tooltip: 'News', + icon: const Icon(Icons.newspaper), + onPressed: /*() {}*/() => _onItemTapped(0), + ), + //if (centerLocations.contains(fabLocation)) const Spacer(), + IconButton( + tooltip: 'Mängel', + icon: const Icon(Icons.warning), + onPressed: () => /*{_pushMangel()}*/ _onItemTapped(1), + ), + IconButton( + tooltip: 'Profil', + icon: const Icon(Icons.person), + onPressed: () => /*{_pushProfile()}*/ _onItemTapped(2), + ), + ], + ), + ), + ) + ); + } +} + +*/ +class _MyHomePageState extends State { + int _selectedIndex = 0; + static const TextStyle optionStyle = + TextStyle(fontSize: 30, fontWeight: FontWeight.bold); + static const List _widgetOptions = [ + Text( + 'Index 0: Home', + style: optionStyle, + ), + Text( + 'Index 1: Business', + style: optionStyle, + ), + Text( + 'Index 2: School', + style: optionStyle, + ), + Text( + 'Index 3: Settings', + style: optionStyle, + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('BottomNavigationBar Sample'), + ), + body: Center( + child: _widgetOptions.elementAt(_selectedIndex), + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + backgroundColor: Colors.red, + ), + BottomNavigationBarItem( + icon: Icon(Icons.business), + label: 'Business', + backgroundColor: Colors.green, + ), + BottomNavigationBarItem( + icon: Icon(Icons.school), + label: 'School', + backgroundColor: Colors.purple, + ), + BottomNavigationBarItem( + icon: Icon(Icons.settings), + label: 'Settings', + backgroundColor: Colors.pink, + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: Colors.amber[800], + onTap: _onItemTapped, + ), + ); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 98436b2..f8679da 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ -//TEST +//TEST, TEST import 'package:flutter/material.dart'; +import 'home.dart'; + void main() { runApp(const MyApp()); } @@ -19,6 +21,7 @@ class MyApp extends StatelessWidget { } } +/* class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); @@ -27,8 +30,8 @@ class MyHomePage extends StatefulWidget { @override State createState() => _MyHomePageState(); } - -class ProfilePage extends StatefulWidget { +*/ +/*class ProfilePage extends StatefulWidget { const ProfilePage({super.key, required this.title}); final String title; @@ -44,9 +47,46 @@ class MangelPage extends StatefulWidget { @override State createState() => _MangelPageState(); -} - +}*/ +/* class _MyHomePageState extends State { + int _selectedIndex = 0; + static const List _widgetOptions = [ + ListView( + padding: const EdgeInsets.all(8), + children: [ + Container( + height: 50, + color: Colors.amber[600], + child: const Center(child: Text('Entry A')), + ), + Container( + height: 50, + color: Colors.amber[500], + child: const Center(child: Text('Entry B')), + ), + Container( + height: 50, + color: Colors.amber[100], + child: const Center(child: Text('Entry C')), + ), + ], + ), + + Text( + 'Index 1: Mängel', + ), + Text( + 'Index 2: Profil', + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + int _counter = 0; void _incrementCounter() { @@ -55,7 +95,7 @@ class _MyHomePageState extends State { }); } - void _pushMangel(){ + /* void _pushMangel(){ Navigator.of(context).push( MaterialPageRoute( builder: (context) => const MangelPage(title: 'Mängel'), @@ -69,7 +109,7 @@ class _MyHomePageState extends State { builder: (context) => const ProfilePage(title: 'Profil'), ), ); - } + }*/ @override Widget build(BuildContext context) { @@ -80,7 +120,7 @@ class _MyHomePageState extends State { title: Text(widget.title), ), body: Center( - +/* child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -93,7 +133,8 @@ class _MyHomePageState extends State { style: Theme.of(context).textTheme.headline4, ), ], - ), + ),*/ + child: _widgetOptions.elementAt(_selectedIndex), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, @@ -110,18 +151,18 @@ class _MyHomePageState extends State { IconButton( tooltip: 'News', icon: const Icon(Icons.newspaper), - onPressed: () {}, + onPressed: /*() {}*/() => _onItemTapped(0), ), //if (centerLocations.contains(fabLocation)) const Spacer(), IconButton( tooltip: 'Mängel', icon: const Icon(Icons.warning), - onPressed: () => {_pushMangel()}, + onPressed: () => /*{_pushMangel()}*/ _onItemTapped(1), ), IconButton( tooltip: 'Profil', icon: const Icon(Icons.person), - onPressed: () => {_pushProfile()}, + onPressed: () => /*{_pushProfile()}*/ _onItemTapped(2), ), ], ), @@ -129,10 +170,23 @@ class _MyHomePageState extends State { ) ); } -} +}*/ +/* class _ProfilePageState extends State { + void _pushMangel(){ + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const MangelPage(title: 'Mängel'), + ), + ); + } + + void _pushNews(){ + Navigator.pop(context); + } + @override Widget build(BuildContext context) { @@ -156,18 +210,18 @@ class _ProfilePageState extends State { IconButton( tooltip: 'News', icon: const Icon(Icons.newspaper), - onPressed: () {}, + onPressed: () => {_pushNews()}, ), //if (centerLocations.contains(fabLocation)) const Spacer(), IconButton( tooltip: 'Mängel', icon: const Icon(Icons.warning), - onPressed: () {}, + onPressed: () => {_pushMangel()}, ), IconButton( tooltip: 'Profil', icon: const Icon(Icons.person), - onPressed: () => {}, + onPressed: () {}, ), ], ), @@ -179,6 +233,17 @@ class _ProfilePageState extends State { class _MangelPageState extends State { + void _pushProfile(){ + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const ProfilePage(title: 'Profil'), + ), + ); + } + + void _pushNews(){ + Navigator.pop(context); + } @override Widget build(BuildContext context) { @@ -221,4 +286,101 @@ class _MangelPageState extends State { ) ); } +}*/ + +//https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html +/* +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } } + +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({super.key}); + + @override + State createState() => _MyStatefulWidgetState(); +} + +class _MyStatefulWidgetState extends State { + int _selectedIndex = 0; + static const TextStyle optionStyle = + TextStyle(fontSize: 30, fontWeight: FontWeight.bold); + static const List _widgetOptions = [ + Text( + 'Index 0: Home', + style: optionStyle, + ), + Text( + 'Index 1: Business', + style: optionStyle, + ), + Text( + 'Index 2: School', + style: optionStyle, + ), + Text( + 'Index 3: Settings', + style: optionStyle, + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('BottomNavigationBar Sample'), + ), + body: Center( + child: _widgetOptions.elementAt(_selectedIndex), + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + backgroundColor: Colors.red, + ), + BottomNavigationBarItem( + icon: Icon(Icons.business), + label: 'Business', + backgroundColor: Colors.green, + ), + BottomNavigationBarItem( + icon: Icon(Icons.school), + label: 'School', + backgroundColor: Colors.purple, + ), + BottomNavigationBarItem( + icon: Icon(Icons.settings), + label: 'Settings', + backgroundColor: Colors.pink, + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: Colors.amber[800], + onTap: _onItemTapped, + ), + ); + } +} +*/