Skip to content

Instantly share code, notes, and snippets.

@Holofox
Created December 24, 2023 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Holofox/8113e38442b877dcad6d3eb5608c78ab to your computer and use it in GitHub Desktop.
Save Holofox/8113e38442b877dcad6d3eb5608c78ab to your computer and use it in GitHub Desktop.
sample-1-suggestion
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: AuthScreen()));
class AuthScreen extends StatelessWidget {
const AuthScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Sign In')),
body: AuthView(
onUsernameChanged: (value) => debugPrint('Username changed: $value'),
onSignedIn: () => ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(const SnackBar(content: Text('Sign in pressed'))),
),
);
}
}
class AuthView extends StatelessWidget {
const AuthView({
super.key,
required this.onUsernameChanged,
required this.onSignedIn,
});
final ValueChanged<String>? onUsernameChanged;
final VoidCallback? onSignedIn;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: CustomScrollView(
physics: const ClampingScrollPhysics(),
slivers: [
SliverList.list(
children: [
TextField(
autofocus: true,
decoration: const InputDecoration(hintText: 'Your username'),
onChanged: onUsernameChanged,
),
const SizedBox(height: 16.0),
],
),
SliverFillRemaining(
hasScrollBody: false,
child: Align(
alignment: Alignment.bottomCenter,
child: FractionallySizedBox(
widthFactor: 1.0,
child: ElevatedButton(
onPressed: onSignedIn,
child: const Text('Sign in'),
),
),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment