knt_ui 1.7.3 knt_ui: ^1.7.3 copied to clipboard
A Flutter package contains all handy widgets for Appixi's future projects
import 'package:flutter/material.dart';
import 'package:knt_ui/knt_ui.dart';
import 'kntgen/generated_page.dart';
import 'repo/poh_repo.dart';
import 'resources.dart';
import 'ui/pages/new_main_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
EasyLocalization.logger.enableBuildModes = [];
KntUi.config(
primaryColor: ColorName.pinkPiano,
secondaryColor: ColorName.intotheStratosphere,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return KntAppWrapper(
supportedLocales: const [Locale(DefinedSetting.defaultLanguageCode)],
debugShowPreviewDevice: false,
appBuilder: (context, devicePreviewLocale, devicePreviewAppBuilder) {
return MaterialApp(
title: 'Flutter Demo',
locale: devicePreviewLocale,
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
builder: devicePreviewAppBuilder,
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
},
);
}
}
abstract class TabIconMain {
static final TabIcon home = TabIcon(
localeKeyTitle: LocaleKeys.main_tabs_home,
activeImagePath: Assets.images.icHomeOn.path,
inactiveImagePath: Assets.images.icHomeOff.path,
);
static final TabIcon garden = TabIcon(
localeKeyTitle: LocaleKeys.main_tabs_help,
activeImagePath: Assets.images.icGardenOn.path,
inactiveImagePath: Assets.images.icGardenOff.path,
);
static final List<TabIcon> values = [home, garden];
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
final List<Photo> _photos = [];
final _needConcurrent = false;
final _onTabChanged = ValueNotifier<int>(0);
@override
void initState() {
super.initState();
_photos.addAll(List.generate(
7,
(index) => Photo(
id: index.toString(),
coverUri: Assets.images.imgCollectionBackyard.path,
mediumSizeUri: Assets.images.imgCollectionBackyard.path,
thumbnailUri: Assets.images.imgCollectionBackyard.path,
storageType: StorageType.assets,
)));
}
Future<String> _loginPoh() async {
final repo = PohRepo();
await repo.init();
return await repo.login(needConcurrent: _needConcurrent);
}
@override
Widget build(BuildContext context) {
return KntBottomNavScaffold(
onTabChanged: _onTabChanged,
appBar: KntAppBar(titlePage: 'KNT demo'),
showLabel: false,
icons: TabIconMain.values,
iconSize: 48.w,
tabs: [
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const KntDefaultToolBar(titlePage: 'Test tool bar 1'),
KntBaseToolBar(
titlePage: 'Test tool bar 2',
leadingIcon: Container(
width: 56.w,
height: 56.w,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: ColorName.black.withAlpha(75),
),
child: Icon(
Icons.arrow_back_rounded,
color: Colors.white,
size: 20.w,
),
),
decoration: const BoxDecoration(
// 272.02deg, #28D581 -6.89%, #33A36D 103.54%
gradient: LinearGradient(
colors: [
Color(0xFF28D581),
Color(0xFF33A36D),
],
begin: Alignment(1.14, 1.1),
end: Alignment(-1.08, -0.73),
stops: [
0.00,
1.00,
],
),
),
),
Container(
height: 248.w,
padding: EdgeInsets.only(bottom: 24.w),
child: KntStaggeredGallery(
direction: Axis.horizontal,
padding: EdgeInsets.only(
left: 24.w,
right: 12.w,
),
photoList: _photos,
),
),
FutureBuilder<String>(
future: _loginPoh(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const KntProgressBar(color: Colors.blue);
}
if (snapshot.hasError) {
return Text(
snapshot.error?.toString() ?? '',
style: TextStyle(
color: Colors.orange,
fontSize: 20.sp,
),
);
}
if (snapshot.hasData) {
return Text(
snapshot.data ?? 'Has empty data',
maxLines: 3,
style: TextStyle(
color: Colors.orange,
fontSize: 20.sp,
),
);
}
return Container(
height: 50.w,
color: Colors.orange,
);
},
),
SizedBox(height: 16.w),
KntSimpleEditText(
defaultValue: 'Type here',
hintText: 'Type me...',
contentPadding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 20.w,
),
),
SizedBox(height: 16.w),
KntSimpleButton(
title: LocaleKeys.main_navigate_web.tr(),
onPressed: () {
KntWebPage.push(
context,
url: 'https://www.google.com',
);
},
),
KntSimpleButton(
title: LocaleKeys.main_navigate_tabHelp.tr(),
onPressed: () {
_onTabChanged.value = 1;
},
),
KntSimpleButton(
title: LocaleKeys.main_navigate_generatedPage.tr(),
onPressed: () {
GeneratedPage.push(context);
},
),
KntSimpleButton(
title: LocaleKeys.main_navigate_mainGeneratedPage.tr(),
onPressed: () {
NewMainPage.push(context);
},
),
KntSimpleButton(
onPressed: () => context.onError('Show fucking noobs!'),
title: 'Show Toast',
textColor: ColorName.black,
borderColor: ColorName.butterTart,
backgroundColor: ColorName.white,
borderWidth: 2.w,
),
KntImage.network(
width: 256.w,
height: 256.w,
uri:
'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.uIgI--NBV7O7HCKmv5Ab2gHaFh%26pid%3DApi&f=1',
),
const KntDivider(),
SizedBox(height: 20.w),
const KntDashDivider(),
SizedBox(height: 20.w),
const KntDefaultIssuingWidget(
errorMessage: 'Abc',
),
const KntChip(text: 'abc'),
KntDefaultImage(
width: 64.w,
height: 64.w,
),
],
),
),
Container(
color: Colors.transparent,
),
],
);
}
}