apptomate_custom_positioned 0.0.1
apptomate_custom_positioned: ^0.0.1 copied to clipboard
A reusable Flutter widget that wraps the standard `Positioned` widget with additional documentation and validation.
example/lib/main.dart
import 'package:apptomate_custom_positioned/apptomate_custom_positioned.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const CustomPositionedWidget(),
);
}
}
/// A demo widget showcasing the [CustomPositioned] widget.
class CustomPositionedWidget extends StatelessWidget {
const CustomPositionedWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Custom Positioned Demo'),
centerTitle: true,
),
body: LayoutBuilder(
builder: (context, constraints) {
return Stack(
children: [
// Background container
Container(
height: 300,
width: double.infinity,
color: Colors.blue[100],
),
// Top-left positioned widget
CustomPositioned(
left: 20,
top: 20,
child: _buildPositionedBox(
color: Colors.red,
size: 80,
text: 'Left-Top',
),
),
// Bottom-right positioned widget
CustomPositioned(
right: 20,
bottom: 20,
child: _buildPositionedBox(
color: Colors.green,
size: 120,
text: 'Right-Bottom',
),
),
// Center positioned widget
CustomPositioned(
left: constraints.maxWidth / 2 - 30, // Centered horizontally
top: 150 - 30, // Centered vertically in the blue container
child: _buildPositionedBox(
color: Colors.purple,
size: 60,
text: 'Center',
),
),
],
);
},
),
);
}
/// Helper method to build a consistent positioned box widget.
Widget _buildPositionedBox({
required Color color,
required double size,
required String text,
}) {
return Container(
height: size,
width: size,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 4,
offset: const Offset(2, 2),
),
],
),
child: Center(
child: Text(
text,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
);
}
}