Skip to content

Commit

Permalink
lesson-25
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshaunjp committed Sep 26, 2019
1 parent 7168863 commit bf1a908
Showing 1 changed file with 66 additions and 49 deletions.
115 changes: 66 additions & 49 deletions brew_crew/lib/screens/home/settings_form.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:brew_crew/models/user.dart';
import 'package:brew_crew/services/database.dart';
import 'package:brew_crew/shared/constants.dart';
import 'package:brew_crew/shared/loading.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SettingsForm extends StatefulWidget {
@override
Expand All @@ -20,56 +24,69 @@ class _SettingsFormState extends State<SettingsForm> {
@override
Widget build(BuildContext context) {

return Form(
key: _formKey,
child: Column(
children: <Widget>[
Text(
'Update your brew settings.',
style: TextStyle(fontSize: 18.0),
),
SizedBox(height: 20.0),
TextFormField(
decoration: textInputDecoration,
validator: (val) => val.isEmpty ? 'Please enter a name' : null,
onChanged: (val) => setState(() => _currentName = val),
),
SizedBox(height: 10.0),
DropdownButtonFormField(
value: _currentSugars ?? '0',
decoration: textInputDecoration,
items: sugars.map((sugar) {
return DropdownMenuItem(
value: sugar,
child: Text('$sugar sugars'),
);
}).toList(),
onChanged: (val) => setState(() => _currentSugars = val ),
),
SizedBox(height: 10.0),
Slider(
value: (_currentStrength ?? 100).toDouble(),
activeColor: Colors.brown[_currentStrength ?? 100],
inactiveColor: Colors.brown[_currentStrength ?? 100],
min: 100.0,
max: 900.0,
divisions: 8,
onChanged: (val) => setState(() => _currentStrength = val.round()),
),
RaisedButton(
color: Colors.pink[400],
child: Text(
'Update',
style: TextStyle(color: Colors.white),
User user = Provider.of<User>(context);

return StreamBuilder<UserData>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if(snapshot.hasData){
UserData userData = snapshot.data;
return Form(
key: _formKey,
child: Column(
children: <Widget>[
Text(
'Update your brew settings.',
style: TextStyle(fontSize: 18.0),
),
SizedBox(height: 20.0),
TextFormField(
initialValue: userData.name,
decoration: textInputDecoration,
validator: (val) => val.isEmpty ? 'Please enter a name' : null,
onChanged: (val) => setState(() => _currentName = val),
),
SizedBox(height: 10.0),
DropdownButtonFormField(
value: _currentSugars ?? userData.sugars,
decoration: textInputDecoration,
items: sugars.map((sugar) {
return DropdownMenuItem(
value: sugar,
child: Text('$sugar sugars'),
);
}).toList(),
onChanged: (val) => setState(() => _currentSugars = val ),
),
SizedBox(height: 10.0),
Slider(
value: (_currentStrength ?? userData.strength).toDouble(),
activeColor: Colors.brown[_currentStrength ?? userData.strength],
inactiveColor: Colors.brown[_currentStrength ?? userData.strength],
min: 100.0,
max: 900.0,
divisions: 8,
onChanged: (val) => setState(() => _currentStrength = val.round()),
),
RaisedButton(
color: Colors.pink[400],
child: Text(
'Update',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
print(_currentName);
print(_currentSugars);
print(_currentStrength);
}
),
],
),
onPressed: () async {
print(_currentName);
print(_currentSugars);
print(_currentStrength);
}
),
],
),
);
} else {
return Loading();
}
}
);
}
}

0 comments on commit bf1a908

Please sign in to comment.