Skip to content

Instantly share code, notes, and snippets.

@manjotsidhu
Last active August 3, 2021 17:41
Show Gist options
  • Save manjotsidhu/85af042a6e0fe151970ccb002f8c608c to your computer and use it in GitHub Desktop.
Save manjotsidhu/85af042a6e0fe151970ccb002f8c608c to your computer and use it in GitHub Desktop.
CV Flutter Scroll to Key Test
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ScrollView(),
);
}
}
class ScrollView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
primary: true,
appBar: new AppBar(
title: const Text('CV Scroll to Widget Test'),
),
body: new SingleChildScrollView(
child: new Column(
children: <Widget>[
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new SizedBox(height: 160.0, width: double.infinity, child: new Card()),
new Card(
color: Colors.red,
key: new GlobalObjectKey('My-Card-Id'),
child: new Text(" Hey I'm Visible! \n\n\n\n\n\ndata "),
)
],
),
),
bottomNavigationBar: new ElevatedButton(
onPressed: () => Scrollable.ensureVisible(new GlobalObjectKey('My-Card-Id').currentContext!),
child: new Text("Scroll to data"),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment