hadss_adaptive_layout 1.0.0-rc.3 copy "hadss_adaptive_layout: ^1.0.0-rc.3" to clipboard
hadss_adaptive_layout: ^1.0.0-rc.3 copied to clipboard

A responsive component plug-in library for multi-device adaptation.

example/lib/main.dart

/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import 'package:example/routes/routers.dart';
import 'package:flutter/material.dart';
import 'package:hadss_adaptive_layout/hadss_adaptive_layout.dart';
import 'package:provider/provider.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  final breakpointProvider = BreakpointProvider();
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(create: (context) => RouteManager()),
      ChangeNotifierProvider(create: (context) => breakpointProvider)
    ],
    child: const MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      initialRoute: '/',
      onGenerateRoute: onGenerateRoute,
    );
  }
}

class BreakpointProvider extends ChangeNotifier {
  WidthBreakpoint _widthBreakpoint = WidthBreakpoint.unknown;
  HeightBreakpoint _heightBreakpoint = HeightBreakpoint.unknown;

  BreakpointProvider() {
    _initBreakpoint();
  }

  Future<void> _initBreakpoint() async {
    final BreakpointData data = await BreakpointManager().init();
    _widthBreakpoint = data.widthBreakpoint;
    _heightBreakpoint = data.heightBreakpoint;
    BreakpointManager().addBreakpointCallback((breakpointData) {
      _widthBreakpoint = breakpointData.widthBreakpoint;
      _heightBreakpoint = breakpointData.heightBreakpoint;
      notifyListeners();
    });
  }

  WidthBreakpoint get widthBreakpoint => _widthBreakpoint;

  HeightBreakpoint get heightBreakpoint => _heightBreakpoint;
}

class RouteManager extends ChangeNotifier {
  final ValueNotifier<List<Page>> pages = ValueNotifier([]);

  pushPage(Page page) {
    final existing = pages.value.any((p) => p.key == page.key);
    if (!existing) {
      pages.value = [...pages.value, page];
    }
  }

  popPage() {
    if (pages.value.length > 1) {
      pages.value = [...pages.value..removeLast()];
    }
  }

  void replaceAll(List<Page> newPages) {
    pages.value = newPages;
  }
}
0
likes
125
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A responsive component plug-in library for multi-device adaptation.

Homepage
Repository

Topics

#adaptive #responsive #layout

Documentation

Documentation
API reference

License

Apache-2.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on hadss_adaptive_layout

Packages that implement hadss_adaptive_layout