Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
58 changes: 47 additions & 11 deletions weekly_assignment_1/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

void _decrementCounter() {
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 _resetToZero() {
setState(() {
_counter = 0;
});
}

_getMessage(int c) {
var output = '';
if (c % 3 == 0) {
output = '${output}fizz';
}
if (c % 5 == 0) {
output = '${output}buzz';
}
return output;
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
Expand Down Expand Up @@ -95,21 +123,29 @@ class _MyHomePageState extends State<MyHomePage> {
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
const Text('You have pushed the button this many times:',
style: TextStyle(fontSize: 25)),
Text('$_counter', style: TextStyle(fontSize: 50)),
Text('${_getMessage(_counter)}', style: TextStyle(fontSize: 50)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
onPressed: _resetToZero,
child: const Icon(Icons.exposure_zero),
),
FloatingActionButton(
onPressed: _decrementCounter,
child: const Icon(Icons.remove)),
FloatingActionButton(
onPressed: _incrementCounter,
child: const Icon(Icons.add),
),
],
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
9 changes: 6 additions & 3 deletions weekly_assignment_1/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void main() {
expect(find.text('1'), findsNothing);
});

testWidgets('Fizz shows up when the counter is divisible by 3', (WidgetTester tester) async {
testWidgets('Fizz shows up when the counter is divisible by 3',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

Expand All @@ -79,7 +80,8 @@ void main() {
expect(find.text('fizz'), findsOneWidget);
});

testWidgets('Buzz shows up when the counter is divisible by 5', (WidgetTester tester) async {
testWidgets('Buzz shows up when the counter is divisible by 5',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

Expand All @@ -93,7 +95,8 @@ void main() {
expect(find.text('buzz'), findsOneWidget);
});

testWidgets('FizzBuzz shows up when the counter is divisible by 3 & 5', (WidgetTester tester) async {
testWidgets('FizzBuzz shows up when the counter is divisible by 3 & 5',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

Expand Down
70 changes: 55 additions & 15 deletions weekly_assignment_2/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(title: 'Text Editing Demo'),
);
}
}
Expand All @@ -48,16 +48,43 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
final _topController = TextEditingController();
final _botController = TextEditingController();
String _output = '';

void _incrementCounter() {
@override
void initState() {
super.initState();
_topController.addListener(() {
final String text = _topController.text;
_topController.value = _topController.value.copyWith(
text: text,
selection:
TextSelection(baseOffset: text.length, extentOffset: text.length),
composing: TextRange.empty,
);
});
_botController.addListener(() {
final String text = _botController.text;
_botController.value = _botController.value.copyWith(
text: text,
selection:
TextSelection(baseOffset: text.length, extentOffset: text.length),
composing: TextRange.empty,
);
});
}

@override
void dispose() {
_topController.dispose();
_botController.dispose();
super.dispose();
}

void _displayResult() {
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++;
_output = 'Hello ${_topController.text} ${_botController.text}';
});
}

Expand Down Expand Up @@ -95,18 +122,31 @@ class _MyHomePageState extends State<MyHomePage> {
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
// Container(child: TextFormField()),
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(6),
child: TextFormField(
controller: _topController,
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'First Name'),
),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(6),
child: TextFormField(
controller: _botController,
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'Last Name'),
),
),
Text(_output, style: const TextStyle(fontSize: 35)),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
onPressed: _displayResult,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
Expand Down