Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HansMuller/266cf806708fffef5440860c3892e1ed to your computer and use it in GitHub Desktop.
Save HansMuller/266cf806708fffef5440860c3892e1ed to your computer and use it in GitHub Desktop.
// TextFormField Android "Failed assertion: 'initialValue == null || controller == null': is not true." Despite controller being null in debug. #18044
// https://github.com/flutter/flutter/issues/18044
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget {
static String tag = 'login-page';
@override
_LoginPageState createState() => new _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
final logo = Hero(
tag: 'hero',
child: CircleAvatar(
backgroundColor: Colors.transparent,
radius: 48.0,
child: new Container(color: Colors.red, width: 48.0, height: 48.0), //Image.asset('assets/logo.png'),
),
);
final email = TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
initialValue: '[email protected]',
controller: null,
decoration: InputDecoration(
hintText: 'Email',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)),
),
);
final password = TextFormField(
autofocus: false,
initialValue: 'some password',
obscureText: true,
controller: null,
decoration: InputDecoration(
hintText: 'Password',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)),
),
);
final loginButton = Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 42.0,
onPressed: () {
Navigator.of(context).pushNamed(HomePage.tag);
},
color: Colors.lightBlueAccent,
child: Text('Log In', style: TextStyle(color: Colors.white)),
),
),
);
final forgotLabel = FlatButton(
child: Text(
'Forgot password?',
style: TextStyle(color: Colors.black54),
),
onPressed: () {},
);
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.only(left: 24.0, right: 24.0),
children: <Widget>[
logo,
SizedBox(height: 48.0),
email,
SizedBox(height: 8.0),
password,
SizedBox(height: 24.0),
loginButton,
forgotLabel
],
),
),
);
}
}
class HomePage extends StatelessWidget {
static String tag = 'home-page';
@override
Widget build(BuildContext context) {
final alucard = Hero(
tag: 'hero',
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircleAvatar(
radius: 72.0,
backgroundColor: Colors.red, //Colors.transparent,
//backgroundImage: AssetImage('assets/alucard.jpg'),
),
),
);
final welcome = Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Welcome Alucard',
style: TextStyle(fontSize: 28.0, color: Colors.white),
),
);
final lorem = Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec hendrerit condimentum mauris id tempor. Praesent eu commodo lacus. Praesent eget mi sed libero eleifend tempor. Sed at fringilla ipsum. Duis malesuada feugiat urna vitae convallis. Aliquam eu libero arcu.',
style: TextStyle(fontSize: 16.0, color: Colors.white),
),
);
final body = Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(28.0),
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.blue,
Colors.lightBlueAccent,
]),
),
child: Column(
children: <Widget>[alucard, welcome, lorem],
),
);
return Scaffold(
body: body,
);
}
}
class MyApp extends StatelessWidget {
final routes = <String, WidgetBuilder>{
LoginPage.tag: (context) => LoginPage(),
HomePage.tag: (context) => HomePage(),
};
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Kodeversitas',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.lightBlue,
//fontFamily: 'Nunito',
),
home: LoginPage(),
routes: routes,
);
}
}
void main() => runApp(MyApp());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment