Skip to main content

DuitViewHost

The DuitViewHost widget is responsible for initializing the associated driver and subscribing to widget tree updates during Duit's operation.

Constructors​

DuitViewHost​

Main constructor accepting a UIDriver (automatically wrapped in XDriver).

DuitViewHost({
required UIDriver driver,
Widget? placeholder,
Widget? child,
bool invertStack = false,
bool showChildInsteadOfPlaceholder = false,
GestureInterceptor? gestureInterceptor,
GestureInterceptorBehavior gestureInterceptorBehavior = GestureInterceptorBehavior.onlyWithAction,
Widget Function(BuildContext context, Object? err)? errorWidgetBuilder,
String viewTag = "",
SliverGridDelegatesRegistry sliverGridDelegatesRegistry = const {},
});

DuitViewHost.withDriver​

Constructor for use with XDriver directly.

const DuitViewHost.withDriver({
required XDriver driver,
// ... other parameters are the same
});

Parameters​

ParameterTypeDefaultDescription
driverUIDriver / XDriver—Driver managing the presentation (required)
placeholderWidget?nullPlaceholder widget during loading
childWidget?nullChild widget to overlay on the Duit presentation
invertStackboolfalseWidget order in Stack (true = child on top)
showChildInsteadOfPlaceholderboolfalseShow child instead of placeholder
gestureInterceptorFunction?nullGesture interceptor
errorWidgetBuilderFunction?nullFunction to build error widget
viewTagString""Tag for presentation identification
sliverGridDelegatesRegistryMap{}Registry of delegates for SliverGrid

Usage Examples​

Basic Usage​

class MyScreen extends StatelessWidget {

Widget build(BuildContext context) {
final driver = XDriver.remote(
transportManager: HttpTransportManager(
url: '/api/layout',
baseUrl: 'https://api.example.com',
),
);

return DuitViewHost.withDriver(
driver: driver,
placeholder: const Center(
child: CircularProgressIndicator(),
),
);
}
}

With Error Handling​

DuitViewHost.withDriver(
driver: driver,
placeholder: const CircularProgressIndicator(),
errorWidgetBuilder: (context, error) {
return Center(
child: Text('Loading error: $error'),
);
},
);

With Gesture Interceptor​

DuitViewHost.withDriver(
driver: driver,
gestureInterceptor: (gestureType, action, data) {
print('Gesture: $gestureType, Action: $action');
},
gestureInterceptorBehavior: GestureInterceptorBehavior.always,
);
tip

For manual widget lifecycle management, use driver.init() and driver.dispose() methods in the corresponding State methods.