diff --git a/weekly_assignment_1/lib/main.dart b/weekly_assignment_1/lib/main.dart index e016029..6f49801 100644 --- a/weekly_assignment_1/lib/main.dart +++ b/weekly_assignment_1/lib/main.dart @@ -11,20 +11,11 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'SIGMobile Assignment 1', 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: const MyHomePage(title: 'Flutter Demo Home Page'), + home: const MyHomePage(title: 'SIGMobile Assignment 1'), ); } } @@ -32,15 +23,6 @@ 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 @@ -49,67 +31,93 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; + String _displayText = "fizzbuzz"; 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++; }); } + void _decrementCounter() { + setState(() { + _counter--; + }); + } + + void _resetToZero() { + setState(() { + _counter = 0; + }); + } + + void _setText() { + setState(() { + _displayText = ""; + if (_counter % 3 == 0) { + _displayText += "fizz"; + } + if (_counter % 5 == 0) { + _displayText += "buzz"; + } + if (_displayText.isEmpty) { + _displayText == "--"; + } + }); + } + @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. + // This method is rerun every time setState is called 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: [ - const Text( - 'You have pushed the button this many times:', + Text( + _displayText, + style: Theme.of(context).textTheme.headline4, ), Text( '$_counter', style: Theme.of(context).textTheme.headline4, ), + const SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ElevatedButton.icon( + onPressed: () { + _incrementCounter(); + _setText(); + }, + label: const Text("increment"), + icon: const Icon(Icons.add), + ), + ElevatedButton.icon( + onPressed: () { + _resetToZero(); + _setText(); + }, + label: const Text("reset"), + icon: const Icon(Icons.exposure_zero), + ), + ElevatedButton.icon( + onPressed: () { + _decrementCounter(); + _setText(); + }, + label: const Text("decrement"), + icon: const Icon(Icons.remove), + ), + ], + ), ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. ); } } diff --git a/weekly_assignment_2/lib/main.dart b/weekly_assignment_2/lib/main.dart index e016029..22c1487 100644 --- a/weekly_assignment_2/lib/main.dart +++ b/weekly_assignment_2/lib/main.dart @@ -7,24 +7,14 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'SIGMobile Weekly Assignment 2', 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: const MyHomePage(title: 'Flutter Demo Home Page'), + home: const MyHomePage(title: 'SIGMobile Week 2'), ); } } @@ -32,15 +22,6 @@ 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 @@ -48,68 +29,74 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; + // Create a text controller. Later, use it to retrieve the + // current value of the TextField. + final firstController = TextEditingController(); + final secondController = TextEditingController(); + + @override + void dispose() { + // Clean up the controller when the widget is removed from the + // widget tree. + firstController.dispose(); + secondController.dispose(); + super.dispose(); + } - void _incrementCounter() { + String _greeting = ""; + String _firstName = ""; + String _lastName = ""; + + void _updateGreeting() { 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++; + _firstName = firstController.text; + _lastName = secondController.text; + _greeting = "Hello $_firstName $_lastName"; }); } @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: [ - const Text( - 'You have pushed the button this many times:', + Padding( + padding: const EdgeInsets.all(8.0), + child: TextField( + controller: firstController, + decoration: const InputDecoration( + label: Text("First Name"), + ), + ), ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, + const SizedBox(height: 8), + Padding( + padding: const EdgeInsets.all(8.0), + child: TextField( + controller: secondController, + decoration: const InputDecoration( + label: Text("Last Name"), + ), + ), ), + const SizedBox(height: 8), + Text( + _greeting, + style: Theme.of(context).textTheme.headlineMedium, + ) ], ), ), floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', + onPressed: _updateGreeting, + tooltip: 'Submit', child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ); } } diff --git a/weekly_assignment_3/lib/main.dart b/weekly_assignment_3/lib/main.dart index e016029..afa7f8e 100644 --- a/weekly_assignment_3/lib/main.dart +++ b/weekly_assignment_3/lib/main.dart @@ -11,17 +11,8 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'SIGMobile Weekly Assignment 3', 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: const MyHomePage(title: 'Flutter Demo Home Page'), @@ -32,15 +23,6 @@ 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 @@ -48,68 +30,48 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; + final List _listTileIndices = List.generate(12, (index) => index); + var listColors = const [ + Color.fromARGB(255, 233, 221, 114), + Color.fromARGB(255, 247, 181, 60), + Color.fromARGB(255, 238, 109, 180), + Color.fromRGBO(236, 138, 204, 1), + Color.fromARGB(255, 208, 138, 218), + Color.fromARGB(255, 169, 105, 243), + Color.fromARGB(255, 136, 112, 243), + Color.fromARGB(255, 115, 133, 236), + Color.fromARGB(255, 121, 198, 233), + Color.fromARGB(255, 155, 225, 247), + Color.fromRGBO(138, 240, 201, 1), + Color.fromARGB(255, 147, 235, 176), + ]; - void _incrementCounter() { + void _removeTileIndex(int index) { 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++; + _listTileIndices.removeAt(index); }); } @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: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], + body: ListView.builder( + padding: const EdgeInsets.all(8), + itemCount: _listTileIndices.length, + itemBuilder: (BuildContext context, int index) => ListTile( + leading: CircleAvatar( + backgroundColor: listColors[_listTileIndices[index]]), + title: const Text('I am a ListTile'), + subtitle: Text('Index: ${_listTileIndices[index]}'), + trailing: IconButton( + icon: const Icon(Icons.delete), + onPressed: () => _removeTileIndex(index), + ), ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. ); } } diff --git a/weekly_assignment_4/lib/main.dart b/weekly_assignment_4/lib/main.dart index e016029..b1825d1 100644 --- a/weekly_assignment_4/lib/main.dart +++ b/weekly_assignment_4/lib/main.dart @@ -7,40 +7,24 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', - 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: const MyHomePage(title: 'Flutter Demo Home Page'), - ); + title: 'SIGMobile Weekly Assignment 4', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Home Page'), + routes: { + '/botNavBar': (BuildContext context) => const BotNavBar(), + '/navRail': (BuildContext context) => const NavRail(), + }); } } 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 @@ -48,68 +32,194 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton( + onPressed: () { + Navigator.pushNamed(context, '/botNavBar'); + }, + child: const Text('Go to bottom navigation bar'), + ), + const SizedBox(width: 45), + TextButton( + onPressed: () { + Navigator.pushNamed(context, '/navRail'); + }, + child: const Text('Go to navigation rail'), + ) + ], + ))); + } +} + +class BotNavBar extends StatefulWidget { + const BotNavBar({super.key}); + + @override + State createState() => _BotNavBarState(); +} + +class _BotNavBarState extends State { + int _selectedIndex = 0; + static const TextStyle optionStyle = TextStyle( + fontSize: 30, + fontWeight: FontWeight.bold, + color: Color.fromARGB(255, 172, 112, 207)); - void _incrementCounter() { + void _selectIndex(int index) { 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++; + _selectedIndex = index; }); } @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), + title: const Text('BottomNavigationBar'), + backgroundColor: const Color.fromARGB(255, 172, 112, 207), ), 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: [ - const Text( - 'You have pushed the button this many times:', + child: IndexedStack( + index: _selectedIndex, + children: [ + Container( + alignment: Alignment.center, + child: const Text( + 'Home', + style: optionStyle, + ), + ), + Container( + alignment: Alignment.center, + child: const Text( + 'Profile', + style: optionStyle, + ), ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, + Container( + alignment: Alignment.center, + child: const Text( + 'Settings', + style: optionStyle, + ), ), ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + ), + BottomNavigationBarItem( + icon: Icon(Icons.person), + label: 'Profile', + ), + BottomNavigationBarItem( + icon: Icon(Icons.settings), + label: 'Settings', + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: const Color.fromARGB(255, 215, 161, 247), + onTap: _selectIndex, + ), + ); + } +} + +class NavRail extends StatefulWidget { + const NavRail({super.key}); + + @override + State createState() => _NavRailState(); +} + +class _NavRailState extends State { + int _selectedIndex = 0; + static const TextStyle optionStyle = TextStyle( + fontSize: 30, + fontWeight: FontWeight.bold, + ); + + void _selectIndex(int index) { + setState(() { + _selectedIndex = index; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('BottomNavigationBar'), + ), + body: Row( + children: [ + NavigationRail( + selectedIndex: _selectedIndex, + onDestinationSelected: _selectIndex, + labelType: NavigationRailLabelType.selected, + destinations: const [ + NavigationRailDestination( + icon: Icon(Icons.favorite_border), + selectedIcon: Icon(Icons.favorite), + label: Text('Favorite'), + ), + NavigationRailDestination( + icon: Icon(Icons.bookmark_border), + selectedIcon: Icon(Icons.book), + label: Text('Bookmark'), + ), + NavigationRailDestination( + icon: Icon(Icons.star_border), + selectedIcon: Icon(Icons.star), + label: Text('Star'), + ), + ], + ), + const VerticalDivider(thickness: 1, width: 1), + // This is the main content. + Expanded( + child: IndexedStack( + index: _selectedIndex, + children: [ + Container( + alignment: Alignment.center, + child: const Text( + 'Favorite', + style: optionStyle, + ), + ), + Container( + alignment: Alignment.center, + child: const Text( + 'Bookmark', + style: optionStyle, + ), + ), + Container( + alignment: Alignment.center, + child: const Text( + 'Star', + style: optionStyle, + ), + ), + ], + ), + ), + ], + ), ); } }