Created with <3 with dartpad.dev.
Created
December 24, 2023 12:35
-
-
Save Holofox/8113e38442b877dcad6d3eb5608c78ab to your computer and use it in GitHub Desktop.
sample-1-suggestion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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