Skip to content

Instantly share code, notes, and snippets.

@IsmailAlamKhan
Created September 26, 2021 19:35
Show Gist options
  • Save IsmailAlamKhan/da8ebfc5eba6add36ac96ce7c485adf0 to your computer and use it in GitHub Desktop.
Save IsmailAlamKhan/da8ebfc5eba6add36ac96ce7c485adf0 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
routes: {
'/': (context) => const Home(),
'/whatever': (context) => Whatever(
data: ModalRoute.of(context)!.settings.arguments as WhateverClass),
},
);
}
}
class Home extends StatefulWidget {
const Home({
Key? key,
}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
final whateverList = List.generate(
Colors.primaries.length,
(index) => WhateverClass(
id: index,
title: Colors.primaries[index].toString(),
color: Colors.primaries[index],
),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Material App Bar'),
),
body: ListView.builder(
itemCount: whateverList.length,
itemBuilder: (_, index) {
final whateverVariable = whateverList[index];
return ListTile(
leading: Text('${whateverVariable.id}'),
title: Text(whateverVariable.title),
tileColor: whateverVariable.color,
onTap: () {
Navigator.of(context).pushNamed(
'/whatever',
arguments: whateverVariable,
);
},
);
},
),
);
}
}
class WhateverClass {
final int id;
final String title;
final Color color;
WhateverClass({required this.id, required this.title, required this.color});
}
class Whatever extends StatelessWidget {
const Whatever({
Key? key,
required this.data,
}) : super(key: key);
final WhateverClass data;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: data.color,
appBar: AppBar(title: Text(data.title)),
body: Center(child: Text('${data.id}')),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment