adaptive_screen_utils 2.3.0 adaptive_screen_utils: ^2.3.0 copied to clipboard
Flutter Package for creating adaptive UIs for different screen sizes.
import 'package:flutter/material.dart';
import 'package:adaptive_screen_utils/adaptive_screen_utils.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Adaptive Screen Utils',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.redAccent),
),
home: const MyHomePage(title: 'Adaptive Screen Utils'),
);
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
final mobile = compact(context);
final tablet = medium(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: mobile
? 2
: tablet
? 4
: 6,
),
children: [
...List.generate(
2 * 4 * 6,
(index) => Container(
color: index.isEven
? Theme.of(context).colorScheme.onPrimaryContainer
: Theme.of(context).colorScheme.onSecondaryContainer,
child: Center(
child: Text(
'Item ${index + 1}',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: index.isEven
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSecondary,
),
),
),
),
),
],
),
);
}
}