Line data Source code
1 : import 'dart:developer'; 2 : 3 : import 'package:flutter/material.dart'; 4 : import 'package:widgetbook/src/models/organizers/organizers.dart'; 5 : import 'package:widgetbook/src/providers/device_provider.dart'; 6 : import 'package:widgetbook/src/providers/injected_theme_provider.dart'; 7 : import 'package:widgetbook/src/providers/injected_theme_state.dart'; 8 : 9 : class DeviceRender extends StatelessWidget { 10 0 : const DeviceRender({ 11 : Key? key, 12 : required this.story, 13 0 : }) : super(key: key); 14 : 15 : final Story story; 16 : 17 0 : ThemeData getInjectedTheme(BuildContext context, InjectedThemeState state) { 18 0 : final brightness = Theme.of(context).brightness; 19 : 20 0 : if (brightness == Brightness.light && state.lightTheme != null) { 21 0 : return state.lightTheme!; 22 : } 23 0 : if (brightness == Brightness.dark && state.darkTheme != null) { 24 0 : return state.darkTheme!; 25 : } 26 : 27 0 : log(''' 28 : No theme was provided for the set brightness. 29 : The theme of widgetbook is used to render your widgets. 30 : This may cause your widgets to look different.'''); 31 0 : return Theme.of(context); 32 : } 33 : 34 0 : @override 35 : Widget build(BuildContext context) { 36 0 : final deviceProvider = DeviceProvider.of(context)!; 37 0 : final state = deviceProvider.state; 38 : 39 0 : final device = state.currentDevice; 40 0 : final resolution = device.resolution; 41 : 42 0 : final themeState = InjectedThemeProvider.of(context)!.state; 43 : 44 0 : return Column( 45 : mainAxisAlignment: MainAxisAlignment.center, 46 0 : children: [ 47 0 : Text(device.name), 48 : const SizedBox( 49 : height: 16, 50 : ), 51 0 : Container( 52 0 : decoration: BoxDecoration( 53 0 : border: Border.all( 54 0 : color: Theme.of(context).brightness == Brightness.dark 55 : ? Colors.white 56 : : Colors.black, 57 : ), 58 : ), 59 0 : width: resolution.logicalSize.width, 60 0 : height: resolution.logicalSize.height, 61 0 : child: MaterialApp( 62 : debugShowCheckedModeBanner: false, 63 0 : theme: getInjectedTheme(context, themeState).copyWith( 64 : pageTransitionsTheme: const PageTransitionsTheme( 65 : builders: { 66 : TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(), 67 : TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(), 68 : }, 69 : ), 70 : ), 71 0 : home: Scaffold( 72 0 : body: story.builder( 73 : context, 74 : ), 75 : ), 76 : ), 77 : ), 78 : ], 79 : ); 80 : } 81 : }