Created
March 21, 2023 23:49
-
-
Save rodydavis/afa1b3152a7dfee078b671f73e688606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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