bweird_widgets 0.1.1
bweird_widgets: ^0.1.1 copied to clipboard
A collection of BWeird widgets and components with GetX implemented
example/lib/main.dart
import 'package:example/components/button_widget.dart';
import 'package:example/components/card_widget.dart';
import 'package:example/components/dialog_widget.dart';
import 'package:example/components/dynamic_layout_widget.dart';
import 'package:example/components/layout_widget.dart';
import 'package:example/components/modal_widget.dart';
import 'package:example/components/scaffold_sidemenu_widget.dart';
import 'package:example/components/scaffold_tabs_widget.dart';
import 'package:example/components/text_widget.dart';
import 'package:flutter/material.dart';
import 'package:bweird_widgets/bweird_widgets.dart';
import 'package:get/route_manager.dart';
MyTheme currentTheme = MyTheme();
class MyTheme with ChangeNotifier {
static bool _isDark = false;
static Color _color = Colors.deepPurple;
ThemeMode currentTheme() {
return _isDark ? ThemeMode.dark : ThemeMode.light;
}
Color currentColor() {
return _color;
}
void onSwitch() {
_isDark = !_isDark;
notifyListeners();
}
void onChangeColor(Color newColor) {
_color = newColor;
notifyListeners();
}
}
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<StatefulWidget> createState() {
return _MyApp();
}
}
class _MyApp extends State<MyApp> {
@override
void initState() {
super.initState();
currentTheme.addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'BWeird Flutter Components',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme:
ColorScheme.fromSeed(seedColor: currentTheme.currentColor()),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: currentTheme.currentColor(),
brightness: Brightness.dark,
),
useMaterial3: true,
),
themeMode: currentTheme.currentTheme(),
home: const MyHomePage(title: 'BWeird Flutter Components'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int selectedTab = 0;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: bodyWidget());
}
Widget bodyWidget() {
return DefaultTabController(
initialIndex: 0,
length: 14,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [themeMode(), colorMode()]),
const SizedBox(height: 10),
const Divider(),
const SizedBox(height: 10),
BWMenuTabbar(
tabs: const [
Tab(text: "Text"),
Tab(text: "Button"),
Tab(text: "Card"),
Tab(text: "Scaffold Side Menu"),
Tab(text: "Scaffold Tabs"),
Tab(text: "Dialog"),
Tab(text: "Modal"),
Tab(text: "Layout"),
Tab(text: "Dynamic Layout"),
Tab(text: "Badge"),
Tab(text: "Dropdown"),
Tab(text: "Scroll List"),
Tab(text: "Pagination"),
Tab(text: "Tabs"),
],
isScrollable: true,
onTap: (tab) {
setState(() {
selectedTab = tab;
});
}),
Expanded(child: onSelectTab())
]));
}
void onToggleTheme() {
currentTheme.onSwitch();
}
Widget themeMode() {
return Row(
children: [
const SizedBox(width: 10),
Switch(
value: Theme.of(context).brightness == Brightness.dark,
onChanged: (isOn) => onToggleTheme(),
),
const SizedBox(width: 10),
BWText.subtitle(
Theme.of(context).brightness == Brightness.dark ? "DARK" : "LIGHT",
isBold: true)
],
);
}
Widget colorMode() {
return PopupMenuButton<Widget>(
color: Colors.black,
child: Row(
children: [
Icon(Icons.square, color: currentTheme.currentColor()),
const Icon(Icons.arrow_drop_down_rounded),
],
),
itemBuilder: (BuildContext context) => [
PopupMenuItem<Widget>(
onTap: () => currentTheme.onChangeColor(Colors.deepOrange),
child: const Icon(Icons.square, color: Colors.deepOrange)),
PopupMenuItem<Widget>(
onTap: () => currentTheme.onChangeColor(Colors.deepPurple),
child: const Icon(Icons.square, color: Colors.deepPurple)),
PopupMenuItem<Widget>(
onTap: () => currentTheme.onChangeColor(Colors.pinkAccent),
child: const Icon(Icons.square, color: Colors.pinkAccent))
],
//import export
);
}
Widget onSelectTab() {
switch (selectedTab) {
case 0:
return const TextExampleWidget();
case 1:
return const ButtonExampleWidget();
case 2:
return const CardExampleWidget();
case 3:
return const ScaffoldSideMenuExampleWidget();
case 4:
return const ScaffoldTabsExampleWidget();
case 5:
return const DialogWidget();
case 6:
return const ModalWidget();
case 7:
return const LayoutWidget();
case 8:
return const DynamicLayoutWidget();
default:
return Container();
}
}
}