mirror of https://github.com/flutter/samples.git
commit
407e5a4ebf
@ -0,0 +1,10 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
Notable changes to the samples in this repository are listed here.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### compass_app
|
||||||
|
|
||||||
|
* Scope `LogoutViewModel` to the home route so it is not recreated on every
|
||||||
|
`HomeHeader` rebuild ([#2604](https://github.com/flutter/samples/issues/2604)).
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../../../data/repositories/booking/booking_repository.dart';
|
||||||
|
import '../../../data/repositories/user/user_repository.dart';
|
||||||
|
import '../../auth/logout/view_models/logout_viewmodel.dart';
|
||||||
|
import '../view_models/home_viewmodel.dart';
|
||||||
|
import 'home_screen.dart';
|
||||||
|
|
||||||
|
class HomeScreenContainer extends StatefulWidget {
|
||||||
|
const HomeScreenContainer({
|
||||||
|
super.key,
|
||||||
|
required this.logoutViewModel,
|
||||||
|
});
|
||||||
|
|
||||||
|
final LogoutViewModel logoutViewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomeScreenContainer> createState() => _HomeScreenContainerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeScreenContainerState extends State<HomeScreenContainer> {
|
||||||
|
late final HomeViewModel _viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_viewModel = HomeViewModel(
|
||||||
|
bookingRepository: context.read<BookingRepository>(),
|
||||||
|
userRepository: context.read<UserRepository>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return HomeScreen(
|
||||||
|
viewModel: _viewModel,
|
||||||
|
logoutViewModel: widget.logoutViewModel,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_viewModel.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +1,16 @@
|
|||||||
import UIKit
|
|
||||||
import Flutter
|
import Flutter
|
||||||
|
import UIKit
|
||||||
|
|
||||||
@UIApplicationMain
|
@main
|
||||||
@objc class AppDelegate: FlutterAppDelegate {
|
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
||||||
override func application(
|
override func application(
|
||||||
_ application: UIApplication,
|
_ application: UIApplication,
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
GeneratedPluginRegistrant.register(with: self)
|
|
||||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||||
|
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue