mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 19:34:54 +00:00
showSpaceBottomSheet in a DefaultAppBar and Routine trigger from the device screen
and fixes github comments and i used this package flutter_html: ^3.0.0-beta.2
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
@ -19,10 +22,21 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
backgroundColor: Colors.transparent,
|
||||
leadingWidth: 200,
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
leading: HomeCubit.getInstance().spaces!.isNotEmpty
|
||||
? HomeCubit.appBarLeading[HomeCubit.bottomNavItems[HomeCubit.pageIndex].label]!
|
||||
: null,
|
||||
actions: HomeCubit.appBarActions[HomeCubit.bottomNavItems[HomeCubit.pageIndex].label],
|
||||
leading: InkWell(
|
||||
onTap: () {
|
||||
final spaces = HomeCubit.getInstance().spaces!;
|
||||
showSpaceBottomSheet(context, spaces);
|
||||
},
|
||||
child: HomeCubit.getInstance().spaces!.isNotEmpty
|
||||
? AbsorbPointer(
|
||||
absorbing: true,
|
||||
child: HomeCubit.appBarLeading[HomeCubit
|
||||
.bottomNavItems[HomeCubit.pageIndex].label]!,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
actions: HomeCubit.appBarActions[
|
||||
HomeCubit.bottomNavItems[HomeCubit.pageIndex].label],
|
||||
));
|
||||
},
|
||||
);
|
||||
@ -31,3 +45,83 @@ class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
Size get preferredSize => Size.fromHeight(Constants.appBarHeight);
|
||||
}
|
||||
|
||||
void showSpaceBottomSheet(BuildContext context, List<SpaceModel> spaces) {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setModalState) {
|
||||
String? selectedSpaceId = HomeCubit.getInstance().selectedSpace?.id;
|
||||
final bool shouldLimitHeight = spaces.length > 5;
|
||||
return Container(
|
||||
constraints: shouldLimitHeight
|
||||
? BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.5,
|
||||
)
|
||||
: const BoxConstraints(),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
decoration: const BoxDecoration(color: Colors.black12),
|
||||
height: 5,
|
||||
width: 50,
|
||||
),
|
||||
ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: spaces.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final space = spaces[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(space.name),
|
||||
],
|
||||
),
|
||||
Radio<String>(
|
||||
value: space.id,
|
||||
groupValue: selectedSpaceId,
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue != null) {
|
||||
setModalState(() {
|
||||
selectedSpaceId = newValue;
|
||||
});
|
||||
HomeCubit.getInstance().changeSelectedSpace(
|
||||
spaces.firstWhere((s) => s.id == newValue),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
child: const Divider(
|
||||
color: Colors.grey,
|
||||
thickness: 0.5,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user