Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created March 21, 2023 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/afa1b3152a7dfee078b671f73e688606 to your computer and use it in GitHub Desktop.
Save rodydavis/afa1b3152a7dfee078b671f73e688606 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 const MaterialApp(
debugShowCheckedModeBanner: false,
home: Example(),
);
}
}
class Example extends StatelessWidget {
const Example({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final source = getSource(size).join('\n');
return Scaffold(
appBar: AppBar(
title: const Text('Adaptive Strings'),
),
body: SingleChildScrollView(
child: Text(source),
),
);
}
Iterable<String> getSource(Size size) sync* {
final columns = List.generate(10, (index) => 'Column $index');
final fakeData = List.generate(1000, (index) {
return {
'name': 'Name $index',
for (final column in columns) column: 'Value $index',
};
});
if (size.width > 720) {
// Render table
yield '| ${columns.join(' | ')} |';
for (final item in fakeData) {
yield '| ${columns.map((column) => item[column]).join(' | ')} |';
}
} else {
// Render list
for (final item in fakeData) {
yield '- ${item['name']}';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment