flutter_stretchable_widgets 0.0.9
flutter_stretchable_widgets: ^0.0.9 copied to clipboard
Lots of interesting and useful widgets, such as picker and expandable components.
// ignore_for_file: avoid_print
import 'package:example/view_factory.dart';
import 'package:flutter/material.dart';
import 'package:flutter_stretchable_widgets/flutter_stretchable_widgets.dart';
import 'package:intl/intl.dart';
void main() => runApp(const App());
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => AppState();
}
class AppState extends State<App> {
@override
Widget build(BuildContext context) {
return const MaterialApp(home: Scaffold(body: Home()));
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => HomeState();
}
class HomeState extends State<Home> {
Couple<DateTime>? changedTimeRange;
Couple<DateTime>? selectedTimeRange;
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: [
/// the left top one
Positioned(
left: 0,
right: 0,
top: 80,
child: ViewFactory.createStretchableWidget(
isInitShowStretchWidget: false,
alignment: Alignment.centerLeft,
),
),
/// the right top one
Positioned(
left: 0,
right: 0,
top: 80,
child: ViewFactory.createStretchableWidget(
isInitShowStretchWidget: false,
alignment: Alignment.centerRight,
isWrappedWithScrollView: true,
text: ViewFactory.textShort,
),
),
/// the left bottom one
Positioned(
left: 0,
right: 0,
bottom: 80,
child: ViewFactory.createStretchableWidget(
isInitShowStretchWidget: true,
alignment: Alignment.centerLeft,
),
),
/// the right bottom one
Positioned(
left: 0,
right: 0,
bottom: 80,
child: ViewFactory.createStretchableWidget(
isInitShowStretchWidget: false,
alignment: Alignment.centerRight,
isWrappedWithScrollView: true,
text: ViewFactory.textLong,
),
),
StatefulBuilder(
builder: (context, mSetState) {
String string4Display(Couple<DateTime>? timeScope) {
if (timeScope == null) return '';
DateFormat first = DateFormat('yyyy/MM/dd HH:mm');
DateFormat second = DateFormat('HH:mm');
return '${first.format(timeScope.first)}-${second.format(timeScope.last)}';
}
return Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 80),
CupertinoActionSheetButton(
title: 'Show Time Range Picker',
onPressed: () async {
changedTimeRange = null;
mSetState(() {});
TimeRangePickerView.show(
context,
onChange: (startDateTime, endDateTime) {
print('CHANGE: startDateTime: $startDateTime, endDateTime: $endDateTime');
changedTimeRange = Couple<DateTime>(startDateTime, endDateTime);
mSetState(() {});
},
onConfirm: (startDateTime, endDateTime) {
print('CONFIRM: startDateTime: $startDateTime, endDateTime: $endDateTime');
selectedTimeRange = Couple<DateTime>(startDateTime, endDateTime);
mSetState(() {});
},
);
},
),
Text(string4Display(changedTimeRange)),
const SizedBox(height: 16),
Text(
string4Display(selectedTimeRange),
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
],
);
},
),
],
);
}
}