Cookbook - Images
CatchedNetworkImage(
imageUrl: "https://my-image.jpeg"
)CachedNetworkImage (
imageUr1: "https://my-image. jpg",
placeholder: (context, ur1) => Text('Loading Surl'),
)CachedNetworkImage (
imageUrl: "https://my-image. jpg",
progressIndicatorBuilder: (_, url, download) {
if (download.progress != null) {
final percent = download.progress! * 100;
return Text ('$percent% done loading');
}
return Text ('Loaded $url!');
},
)Container(
decoration: BoxDecoration(
image: CachedNetworkImageProvider(
'https://my-image.jpg',
),
),
)Cookbook - Design
Add a Drawer to a screen
Display a snackbar
- Scaffold Messenger > 기존 SnackBar는 새 페이지로 이동하지 않는다. 이때 Scaffold Messenger를 사용한다. Scaffold Messenger는 모든 스캐폴드의 상위에서 작동하게 된다. 새로운 스캐폴드가 실행될 때마다 상위 Scaffold Messenger를 탐색하게 되고, looks up the tree for an ancestor scaffold and subscribes to snack bar events 한다. > > >  > 
>
```dart
ScaffoldMessenger.of(Context)
final _scaffoldKey = GlobalKey<ScaffoldMessengerState>();
MatreialApp(
scaffoldMessengerKey: _scaffoldKey,
)
final ScaffoldMessengerState _scaffold = _scaffoldkey.currentState;
scaffoldMessengerState.showSnackBar(
SnackBar(...),
)
```
Update the UI based on orientation
Use themes to share colors and font styles
```dart MaterialApp( theme: ThemeData(), darkTheme: ThemeData.dark(), ) ``` ```dart MaterialApp( colorScheme: ColorScheme.fromSwatch( primarySwatch: Color.orange, ), textTheme: GoogleFonts.emilysCandyTextTheme(), scaffoldBackgroundColor: Colors.orange[100], ) ``` Theme 위젯으로 완전히 새로운 데이터를 제공하거나 ```dart Theme( data: ThemeData(...), child: MyWidget(), ) ``` 기존 테마를 복사하여 원하는 대로 활용할 수 있다. ```dart Theme( data: Theme.of(context).copyWith(...), child: MyWidget(), ) ```Work with tabs
Cookbook - Lists
Cookbook - Navigation
In Android, a route is equivalent to an Activity. In iOS, a route is equivalent to a ViewController. In Flutter, a route is just a widget. This recipe uses the Navigator to navigate to a new route.
To switch to a new route, use the
[Navigator.push()](https://api.flutter.dev/flutter/widgets/Navigator/push.html)method. Thepush()method adds aRouteto the stack of routes managed by theNavigator.
By using the
[Navigator.pop()](https://api.flutter.dev/flutter/widgets/Navigator/pop.html)method. Thepop()method removes the currentRoutefrom the stack of routes managed by theNavigator.
- Animate a widget across screens
- c618b76fc6cd821971a2565dd3705a5e
- Navigate to a new screen and back
- 733813794a9a6717615b0bb2f5292f2c
- Navigate with named routes
To work with named routes, use the
[Navigator.pushNamed()](https://api.flutter.dev/flutter/widgets/Navigator/pushNamed.html)function. This example replicates the functionality from the original recipe, demonstrating how to use named routes using the following steps:
- Create two screens.
- Define the routes.
- Navigate to the second screen using
Navigator.pushNamed().- Return to the first screen using
Navigator.pop().
Show a snackbar on the home screen with the selection. Now that you’re Launching a selection screen and awaiting the result, you’ll want to do something with the information that’s returned. In this case, show a snackbar displaying the result by using the
_navigateAndDisplaySelection()method inSelectionButton:
// A method that launches the SelectionScreen and awaits the result from
// Navigator.pop.
Future<void> _navigateAndDisplaySelection(BuildContext context) async {
// Navigator.push returns a Future that completes after calling
// Navigator.pop on the Selection Screen.
final result = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SelectionScreen()),
);
// When a BuildContext is used from a StatefulWidget, the mounted property
// must be checked after an asynchronous gap.
if (!mounted) return;
// After the Selection Screen returns a result, hide any previous snackbars
// and show the new result.
ScaffoldMessenger.of(context)
..removeCurrentSnackBar()
..showSnackBar(SnackBar(content: Text('$result')));
}
Cookbook - Forms