Skip to content

Commit

Permalink
More example app improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Jun 18, 2024
1 parent 8f5ce14 commit 37fc1bf
Show file tree
Hide file tree
Showing 37 changed files with 2,386 additions and 1,006 deletions.
286 changes: 14 additions & 272 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,261 +7,10 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'src/screens/home/home.dart';
import 'src/screens/home/map_view/state/region_selection_provider.dart';
import 'src/screens/initialisation_error/initialisation_error.dart';
import 'src/screens/store_editor/store_editor.dart';
import 'src/shared/misc/shared_preferences.dart';
import 'src/shared/state/general_provider.dart';

/*void main() {
runApp(RootWidget());
}
class RootWidget extends StatelessWidget {
const RootWidget({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeWidget(),
);
}
}
class HomeWidget extends StatefulWidget {
const HomeWidget({super.key});
@override
State<HomeWidget> createState() => _HomeWidgetState();
}
class _HomeWidgetState extends State<HomeWidget> {
final bottomSheetOuterController = DraggableScrollableController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox.expand(
child: ColoredBox(
color: Colors.red,
child: Center(
child: ElevatedButton(
onPressed: () {
print(bottomSheetOuterController.isAttached);
bottomSheetOuterController.animateTo(
0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
},
child: Text('expand'),
),
),
),
),
bottomSheet: DraggableScrollableSheet(
initialChildSize: 0.3,
expand: false,
controller: bottomSheetOuterController,
builder: (context, innerController) => ColoredBox(
color: Colors.blue,
child: SizedBox.expand(
child: Center(
child: ElevatedButton(
onPressed: () {
print(bottomSheetOuterController.isAttached);
bottomSheetOuterController.animateTo(
0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
},
child: Text('expand'),
),
),
),
),
),
/*bottomNavigationBar: NavigationBar(
selectedIndex: selectedTab,
destinations: const [
NavigationDestination(
icon: Icon(Icons.map_outlined),
selectedIcon: Icon(Icons.map),
label: 'Map',
),
NavigationDestination(
icon: Icon(Icons.download_outlined),
selectedIcon: Icon(Icons.download),
label: 'Download',
),
],
onDestinationSelected: (i) {
if (i == 1) {
bottomSheetOuterController.animateTo(
0,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
} else {
bottomSheetOuterController.animateTo(
0.3,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
}
},
),*/
);
}
}
class CustomBottomSheet extends StatefulWidget {
const CustomBottomSheet({
super.key,
required this.controller,
});
final DraggableScrollableController controller;
@override
State<CustomBottomSheet> createState() => _CustomBottomSheetState();
}
class _CustomBottomSheetState extends State<CustomBottomSheet> {
@override
Widget build(BuildContext context) {
return DraggableScrollableSheet(
initialChildSize: 0.3,
minChildSize: 0,
snap: true,
expand: false,
snapSizes: const [0.3],
controller: widget.controller,
builder: (context, innerController) => ColoredBox(
color: Colors.blue,
child: SizedBox.expand(
child: Center(
child: ElevatedButton(
onPressed: () {
print(widget.controller.isAttached);
widget.controller.animateTo(
0.5,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
);
},
child: Text('expand'),
),
),
),
),
/* DelayedControllerAttachmentBuilder(
listenable: widget.controller,
builder: (context, child) {
double radius = 18;
double calcHeight = 0;
if (widget.controller.isAttached) {
final maxHeight = widget.controller.sizeToPixels(1);
final oldValue = widget.controller.pixels;
final oldMax = maxHeight;
final oldMin = maxHeight - radius;
const newMax = 0.0;
final newMin = radius;
radius = ((((oldValue - oldMin) * (newMax - newMin)) /
(oldMax - oldMin)) +
newMin)
.clamp(0, radius);
calcHeight = screenTopPadding -
constraints.maxHeight +
widget.controller.pixels;
}
return ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(radius),
topRight: Radius.circular(radius),
),
child: Column(
children: [
DelayedControllerAttachmentBuilder(
listenable: innerController,
builder: (context, _) => SizedBox(
height: calcHeight.clamp(0, screenTopPadding),
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
color: innerController.hasClients &&
innerController.offset != 0
? Theme.of(context)
.colorScheme
.surfaceContainerLowest
: Theme.of(context).colorScheme.surfaceContainerLow,
),
),
),
Expanded(
child: ColoredBox(
color: Theme.of(context).colorScheme.surfaceContainerLow,
child: child,
),
),
],
),
);
},
child: Stack(
children: [
BottomSheetScrollableProvider(
innerScrollController: innerController,
child: widget.child,
),
IgnorePointer(
child: DelayedControllerAttachmentBuilder(
listenable: widget.controller,
builder: (context, _) {
if (!widget.controller.isAttached) {
return const SizedBox.shrink();
}
final calcHeight = BottomSheet.topPadding -
(screenTopPadding -
constraints.maxHeight +
widget.controller.pixels);
return SizedBox(
height: calcHeight.clamp(0, BottomSheet.topPadding),
width: constraints.maxWidth,
child: Semantics(
label: MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
container: true,
child: Center(
child: Container(
height: 4,
width: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Theme.of(context)
.colorScheme
.onSurfaceVariant
.withOpacity(0.4),
),
),
),
),
);
},
),
),
],
),
),*/
);
}
}*/

void main() async {
WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -288,20 +37,21 @@ class _AppContainer extends StatelessWidget {

static final _routes = <String,
({
PageRouteBuilder<dynamic> Function({
required Widget Function(
BuildContext,
Animation<double>,
Animation<double>,
) pageBuilder,
required RouteSettings settings,
})? custom,
Widget Function(BuildContext) std,
Widget Function(BuildContext)? std,
PageRoute Function(BuildContext, RouteSettings)? custom,
})>{
HomeScreen.route: (
std: (BuildContext context) => const HomeScreen(),
custom: null,
),
StoreEditorPopup.route: (
std: null,
custom: (context, settings) => MaterialPageRoute(
builder: (context) => const StoreEditorPopup(),
settings: settings,
fullscreenDialog: true,
),
),
/*ManageOfflineScreen.route: (
std: (BuildContext context) => ManageOfflineScreen(),
custom: null,
Expand Down Expand Up @@ -346,7 +96,7 @@ class _AppContainer extends StatelessWidget {
brightness: Brightness.light,
useMaterial3: true,
textTheme: GoogleFonts.ubuntuTextTheme(ThemeData.light().textTheme),
colorSchemeSeed: Colors.orange,
colorSchemeSeed: Colors.teal,
switchTheme: SwitchThemeData(
thumbIcon: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected)
Expand Down Expand Up @@ -393,16 +143,8 @@ class _AppContainer extends StatelessWidget {
initialRoute: HomeScreen.route,
onGenerateRoute: (settings) {
final route = _routes[settings.name]!;
if (route.custom != null) {
return route.custom!(
pageBuilder: (context, _, __) => route.std(context),
settings: settings,
);
}
return MaterialPageRoute(
builder: route.std,
settings: settings,
);
if (route.custom != null) return route.custom!(context, settings);
return MaterialPageRoute(builder: route.std!, settings: settings);
},
),
);
Expand Down
Loading

0 comments on commit 37fc1bf

Please sign in to comment.