mirror of
https://github.com/flutter/samples.git
synced 2025-11-14 11:28:36 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -19,18 +19,14 @@ class DashboardPage extends StatelessWidget {
|
||||
future: appState.api!.categories.list(),
|
||||
builder: (context, futureSnapshot) {
|
||||
if (!futureSnapshot.hasData) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return StreamBuilder<List<Category>>(
|
||||
initialData: futureSnapshot.data,
|
||||
stream: appState.api!.categories.subscribe(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data == null) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return Dashboard(snapshot.data);
|
||||
},
|
||||
@@ -56,13 +52,9 @@ class Dashboard extends StatelessWidget {
|
||||
),
|
||||
children: [
|
||||
...categories!.map(
|
||||
(category) => Card(
|
||||
child: CategoryChart(
|
||||
category: category,
|
||||
api: api,
|
||||
),
|
||||
),
|
||||
)
|
||||
(category) =>
|
||||
Card(child: CategoryChart(category: category, api: api)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -27,15 +27,17 @@ class _EntriesPageState extends State<EntriesPage> {
|
||||
return Column(
|
||||
children: [
|
||||
CategoryDropdown(
|
||||
api: appState.api!.categories,
|
||||
onSelected: (category) => setState(() => _selected = category)),
|
||||
api: appState.api!.categories,
|
||||
onSelected: (category) => setState(() => _selected = category),
|
||||
),
|
||||
Expanded(
|
||||
child: _selected == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: EntriesList(
|
||||
category: _selected,
|
||||
api: appState.api!.entries,
|
||||
),
|
||||
child:
|
||||
_selected == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: EntriesList(
|
||||
category: _selected,
|
||||
api: appState.api!.entries,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -46,10 +48,8 @@ class EntriesList extends StatefulWidget {
|
||||
final Category? category;
|
||||
final EntryApi api;
|
||||
|
||||
EntriesList({
|
||||
this.category,
|
||||
required this.api,
|
||||
}) : super(key: ValueKey(category?.id));
|
||||
EntriesList({this.category, required this.api})
|
||||
: super(key: ValueKey(category?.id));
|
||||
|
||||
@override
|
||||
State<EntriesList> createState() => _EntriesListState();
|
||||
@@ -99,11 +99,7 @@ class EntryTile extends StatelessWidget {
|
||||
final Category? category;
|
||||
final Entry? entry;
|
||||
|
||||
const EntryTile({
|
||||
this.category,
|
||||
this.entry,
|
||||
super.key,
|
||||
});
|
||||
const EntryTile({this.category, this.entry, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -131,26 +127,25 @@ class EntryTile extends StatelessWidget {
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final bool? shouldDelete = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete entry?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('Delete entry?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (shouldDelete != null && shouldDelete) {
|
||||
await appState.api!.entries.delete(category!.id!, entry!.id!);
|
||||
scaffoldMessenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Entry deleted'),
|
||||
),
|
||||
const SnackBar(content: Text('Entry deleted')),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,10 +14,7 @@ import 'entries.dart';
|
||||
class HomePage extends StatefulWidget {
|
||||
final VoidCallback onSignOut;
|
||||
|
||||
const HomePage({
|
||||
required this.onSignOut,
|
||||
super.key,
|
||||
});
|
||||
const HomePage({required this.onSignOut, super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
@@ -38,7 +35,7 @@ class _HomePageState extends State<HomePage> {
|
||||
onPressed: () => _handleSignOut(),
|
||||
child: const Text('Sign Out'),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
currentIndex: _pageIndex,
|
||||
destinations: const [
|
||||
@@ -90,23 +87,24 @@ class _HomePageState extends State<HomePage> {
|
||||
Future<void> _handleSignOut() async {
|
||||
var shouldSignOut = await (showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Are you sure you want to sign out?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('No'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('Are you sure you want to sign out?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('No'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Yes'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Yes'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
if (shouldSignOut == null || !shouldSignOut) {
|
||||
|
||||
@@ -10,18 +10,12 @@ class SignInPage extends StatelessWidget {
|
||||
final Auth auth;
|
||||
final ValueChanged<User> onSuccess;
|
||||
|
||||
const SignInPage({
|
||||
required this.auth,
|
||||
required this.onSuccess,
|
||||
super.key,
|
||||
});
|
||||
const SignInPage({required this.auth, required this.onSuccess, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: SignInButton(auth: auth, onSuccess: onSuccess),
|
||||
),
|
||||
body: Center(child: SignInButton(auth: auth, onSuccess: onSuccess)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,11 +24,7 @@ class SignInButton extends StatefulWidget {
|
||||
final Auth auth;
|
||||
final ValueChanged<User> onSuccess;
|
||||
|
||||
const SignInButton({
|
||||
required this.auth,
|
||||
required this.onSuccess,
|
||||
super.key,
|
||||
});
|
||||
const SignInButton({required this.auth, required this.onSuccess, super.key});
|
||||
|
||||
@override
|
||||
State<SignInButton> createState() => _SignInButtonState();
|
||||
@@ -97,10 +87,8 @@ class _SignInButtonState extends State<SignInButton> {
|
||||
}
|
||||
|
||||
void _showError() {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Unable to sign in.'),
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Unable to sign in.')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user