Skip to content

Commit

Permalink
New edition (kodecocodes#159)
Browse files Browse the repository at this point in the history
* add runspacing

* add runspacing to all chapters

* use theme instead of hardcode style

* update all project files to use theme instead of hardcode style

* update to headline 6

* fix #422

* remove the `k` prefix, effective dart does not recommend this

* Better handle error

* Add error handling

* FPE - Fix leftover k-prefixed consts

* Chapter 14 - Handle error (kodecocodes#154)

* Handle error

* Handle error

* Add collection import

* Chapter 15 - Handle error (kodecocodes#156)

* Handle error

* FPE - Add moor specific version

Co-authored-by: Cesare Rocchi <[email protected]>

* Errata init (kodecocodes#160)

* chapter 8 starter and final, move super.initState beginning

* chapter 7 init state

* update super.initState chapter 6

* update chapter 5 challenge init state

Co-authored-by: Vincent Ngo <[email protected]>
Co-authored-by: Michael Katz <[email protected]>
Co-authored-by: Kevin Moore <[email protected]>
  • Loading branch information
4 people authored Nov 30, 2021
1 parent f7d9e37 commit 56c5cc1
Show file tree
Hide file tree
Showing 40 changed files with 213 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _RecipeDetailState extends State<RecipeDetail> {
// 10
min: 1,
max: 10,
divisions: 10,
divisions: 9,
// 11
label: '${_sliderVal * widget.recipe.servings} servings',
// 12
Expand Down
4 changes: 3 additions & 1 deletion 03-basic-widgets/projects/final/lib/card3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class Card3 extends StatelessWidget {
alignment: WrapAlignment.start,
// 13
spacing: 12,
// 14
//14
runSpacing: 12,
// 15
children: [
Chip(
label: Text('Healthy',
Expand Down
1 change: 1 addition & 0 deletions 04-understanding-widgets/projects/final/lib/card3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: [
Chip(
label: Text(
Expand Down
1 change: 1 addition & 0 deletions 04-understanding-widgets/projects/starter/lib/card3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: [
Chip(
label: Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class _ExploreScreenState extends State<ExploreScreen> {

@override
void initState() {
super.initState();
_controller = ScrollController();
_controller.addListener(_scrollListener);
super.initState();
}

void _scrollListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips()),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class EmptyGroceryScreen extends StatelessWidget {
child: Image.asset('assets/fooderlich_assets/empty_list.png'),
),
),
const Text(
Text(
'No Groceries',
style: TextStyle(fontSize: 21.0),
style: Theme.of(context).textTheme.headline6,
),
const SizedBox(height: 16.0),
const Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {

@override
void initState() {
super.initState();
// 1
final originalItem = widget.originalItem;
if (originalItem != null) {
Expand All @@ -59,8 +60,6 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {
_name = _nameController.text;
});
});

super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
2 changes: 1 addition & 1 deletion 07-routes-and-navigation/projects/final/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class _FooderlichState extends State<Fooderlich> {

@override
void initState() {
super.initState();
_appRouter = AppRouter(
appStateManager: _appStateManager,
groceryManager: _groceryManager,
profileManager: _profileManager,
);
super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class EmptyGroceryScreen extends StatelessWidget {
child: Image.asset('assets/fooderlich_assets/empty_list.png'),
),
),
const Text(
Text(
'No Groceries',
style: TextStyle(fontSize: 21.0),
style: Theme.of(context).textTheme.headline6,
),
const SizedBox(height: 16.0),
const Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {

@override
void initState() {
super.initState();
final originalItem = widget.originalItem;
if (originalItem != null) {
_name = originalItem.name;
Expand All @@ -377,8 +378,6 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {
_name = _nameController.text;
});
});

super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class EmptyGroceryScreen extends StatelessWidget {
child: Image.asset('assets/fooderlich_assets/empty_list.png'),
),
),
const Text(
Text(
'No Groceries',
style: TextStyle(fontSize: 21.0),
style: Theme.of(context).textTheme.headline6,
),
const SizedBox(height: 16.0),
const Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {

@override
void initState() {
super.initState();
final originalItem = widget.originalItem;
if (originalItem != null) {
_name = originalItem.name;
Expand All @@ -374,8 +375,6 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {
_name = _nameController.text;
});
});

super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
2 changes: 1 addition & 1 deletion 08-deep-links-and-web-URLs/projects/final/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class _FooderlichState extends State<Fooderlich> {

@override
void initState() {
super.initState();
_appRouter = AppRouter(
appStateManager: _appStateManager,
groceryManager: _groceryManager,
profileManager: _profileManager,
);
super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class AppLink {
// 1
static const String kHomePath = '/home';
static const String kOnboardingPath = '/onboarding';
static const String kLoginPath = '/login';
static const String kProfilePath = '/profile';
static const String kItemPath = '/item';
static const String homePath = '/home';
static const String onboardingPath = '/onboarding';
static const String loginPath = '/login';
static const String profilePath = '/profile';
static const String itemPath = '/item';
// 2
static const String kTabParam = 'tab';
static const String kIdParam = 'id';
static const String tabParam = 'tab';
static const String idParam = 'id';
// 3
String? location;
// 4
Expand All @@ -28,9 +28,9 @@ class AppLink {
final uri = Uri.parse(location);
final params = uri.queryParameters;
// 3
final currentTab = int.tryParse(params[AppLink.kTabParam] ?? '');
final currentTab = int.tryParse(params[AppLink.tabParam] ?? '');
// 4
final itemId = params[AppLink.kIdParam];
final itemId = params[AppLink.idParam];
// 5
final link = AppLink(
location: uri.path,
Expand All @@ -51,27 +51,27 @@ class AppLink {
// 2
switch (location) {
// 3
case kLoginPath:
return kLoginPath;
case loginPath:
return loginPath;
// 4
case kOnboardingPath:
return kOnboardingPath;
case onboardingPath:
return onboardingPath;
// 5
case kProfilePath:
return kProfilePath;
case profilePath:
return profilePath;
// 6
case kItemPath:
var loc = '$kItemPath?';
case itemPath:
var loc = '$itemPath?';
loc += addKeyValPair(
key: kIdParam,
key: idParam,
value: itemId,
);
return Uri.encodeFull(loc);
// 7
default:
var loc = '$kHomePath?';
var loc = '$homePath?';
loc += addKeyValPair(
key: kTabParam,
key: tabParam,
value: currentTab.toString(),
);
return Uri.encodeFull(loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ class AppRouter extends RouterDelegate<AppLink>

AppLink getCurrentPath() {
if (!appStateManager.isLoggedIn) {
return AppLink(location: AppLink.kLoginPath);
return AppLink(location: AppLink.loginPath);
} else if (!appStateManager.isOnboardingComplete) {
return AppLink(location: AppLink.kOnboardingPath);
return AppLink(location: AppLink.onboardingPath);
} else if (profileManager.didSelectUser) {
return AppLink(location: AppLink.kProfilePath);
return AppLink(location: AppLink.profilePath);
} else if (groceryManager.isCreatingNewItem) {
return AppLink(location: AppLink.kItemPath);
return AppLink(location: AppLink.itemPath);
} else if (groceryManager.selectedGroceryItem != null) {
final id = groceryManager.selectedGroceryItem?.id;
return AppLink(
location: AppLink.kItemPath,
location: AppLink.itemPath,
itemId: id,
);
} else {
return AppLink(
location: AppLink.kHomePath,
location: AppLink.homePath,
currentTab: appStateManager.getSelectedTab);
}
}
Expand All @@ -123,11 +123,11 @@ class AppRouter extends RouterDelegate<AppLink>
// 2
switch (newLink.location) {
// 3
case AppLink.kProfilePath:
case AppLink.profilePath:
profileManager.tapOnProfile(true);
break;
// 4
case AppLink.kItemPath:
case AppLink.itemPath:
final itemId = newLink.itemId;
// 5
if (itemId != null) {
Expand All @@ -140,7 +140,7 @@ class AppRouter extends RouterDelegate<AppLink>
profileManager.tapOnProfile(false);
break;
// 8
case AppLink.kHomePath:
case AppLink.homePath:
// 9
appStateManager.goToTab(newLink.currentTab ?? 0);
// 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class EmptyGroceryScreen extends StatelessWidget {
child: Image.asset('assets/fooderlich_assets/empty_list.png'),
),
),
const Text(
Text(
'No Groceries',
style: TextStyle(fontSize: 21.0),
style: Theme.of(context).textTheme.headline6,
),
const SizedBox(height: 16.0),
const Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {

@override
void initState() {
super.initState();
final originalItem = widget.originalItem;
if (originalItem != null) {
_name = originalItem.name;
Expand All @@ -379,8 +380,6 @@ class _GroceryItemScreenState extends State<GroceryItemScreen> {
_name = _nameController.text;
});
});

super.initState();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Card3 extends StatelessWidget {
child: Wrap(
alignment: WrapAlignment.start,
spacing: 12,
runSpacing: 12,
children: createTagChips(),
),
),
Expand Down
Loading

0 comments on commit 56c5cc1

Please sign in to comment.