CopyPastor

Detecting plagiarism made easy.

Score: 0.8043962121009827; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-01-10
by Abdul Mateen

Original Post

Original - Posted on 2020-04-07
by user12208004



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Use Scaffold key for showing snackbar.
``` class SignIn extends StatefulWidget { @override _SignInState createState() { return _SignInState(); } }
class _SignInState extends State<SignIn> { final _formKey = GlobalKey<FormState>(); final _scaffoldKey = GlobalKey<ScaffoldState>();
@override Widget build(BuildContext context) { return MaterialApp( title: "Hello", home: Scaffold( key: _scaffoldKey, body: Center( child: ListView( shrinkWrap: true, children: <Widget>[ Center( child: Form( key: _formKey, child: Column(children: <Widget>[ Container( child: Column( children: <Widget>[ Container( child: Row( children: <Widget>[ ElevatedButton( child: Text("Login"), onPressed: () async { _scaffoldKey.currentState.showSnackBar( SnackBar( content: Text("Hello there!"), ), ); }) ], ), ) ], ), ) ]), ), ), ], ), ), ), ); } } ```
najeira's solution is easy and simple, but you can get the same and more flexible result without touching index.
Instead of using listView, you could use **CustomScrollView & SliverList** which is functionally the same as listView.
``` return Scaffold( body: CustomScrollView( slivers: <Widget>[ SliverToBoxAdapter( // you could add any widget child: ListTile( leading: CircleAvatar( backgroundColor: Colors.transparent, ), title: Row( children: <Widget>[ Expanded(child: Text("First Name")), Expanded(child: Text("Last Name")), Expanded(child: Text("City")), Expanded(child: Text("Id")), ], ), ), ), SliverList( delegate: SliverChildBuilderDelegate( (context, index) { return InkWell( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => APIDetailView(data[index])), ); }, child: ListTile( //return ListTile( leading: CircleAvatar( backgroundColor: Colors.blue, child: Text(data[index]["FirstName"][0]), ), title: Row( children: <Widget>[ Expanded(child: Text(data[index]["FirstName"])), Expanded(child: Text(data[index]["LastName"])), Expanded(child: Text(data[index]["Bill_City"])), Expanded(child: Text(data[index]["Customer_Id"])), ], ), ), ); }, childCount: data == null ? 0 : data.length, ), ), ], ), ); ```

        
Present in both answers; Present only in the new answer; Present only in the old answer;