How to get a glitch effect on widgets in flutter
How could I get a glitch effect, like this, on widgets(or images) in flutter. I want it animated but I'm not sure how I could achieve that effect.
I'm trying to have this as my splash screen for a website.
See also questions close to this topic
-
fatal error: 'Flutter/Flutter.h' file not found
when I compile my project in mac book pro, shows this error:
Xcode's output: ↳ In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/JavaScriptChannelHandler.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/JavaScriptChannelHandler.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences-0.5.12+4/ios/Classes/FLTSharedPreferencesPlugin.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences-0.5.12+4/ios/Classes/FLTSharedPreferencesPlugin.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FlutterWebView.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FlutterWebView.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTWebViewFlutterPlugin.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTWebViewFlutterPlugin.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTWKNavigationDelegate.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTWKNavigationDelegate.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTCookieManager.m:5: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/webview_flutter-0.3.24/ios/Classes/FLTCookieManager.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/wakelock-0.1.4+2/ios/Classes/WakelockPlugin.m:1: /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/wakelock-0.1.4+2/ios/Classes/WakelockPlugin.h:1:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. /Users/dolphin/.pub-cache/hosted/pub.flutter-io.cn/video_player-0.10.12+5/ios/Classes/messages.m:4:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h>
I am tried this way to fix it:
~/apps/flutter/bin/flutter clean
did not work, then I tried this way:
$ pod install /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/dolphin in PATH, mode 040777 Analyzing dependencies Downloading dependencies Generating Pods project Integrating client project Pod installation complete! There are 15 dependencies from the Podfile and 18 total pods installed. [!] A license was specified in podspec `sentry_flutter` but the file does not exist - /Users/dolphin/Documents/GitHub/cruise-open/ios/.symlinks/plugins/LICENSE [!] Unable to read the license file `../../LICENSE` for the spec `sentry_flutter (0.0.1)` [!] Unable to read the license file `../../LICENSE` for the spec `sentry_flutter (0.0.1)` [!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`). (base)
still not work, why did this happen and what should I do fix it? This is my channel:
$ ~/apps/flutter/bin/flutter doctor -v [✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.7 19H114, locale en-CN) • Flutter version 1.20.4 at /Users/dolphin/apps/flutter • Framework revision fba99f6cf9 (4 months ago), 2020-09-14 15:32:52 -0700 • Engine revision d1bc06f032 • Dart version 2.9.2 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/dolphin/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.3, Build version 12C33 • CocoaPods version 1.10.0 [!] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [!] IntelliJ IDEA Community Edition (version 2020.3.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.dev/intellij-setup/#installing-the-plugins [!] IntelliJ IDEA Ultimate Edition (version 2019.2.2) • IntelliJ at /Users/dolphin/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.dev/intellij-setup/#installing-the-plugins [✓] VS Code (version 1.52.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.18.1 [✓] Connected device (1 available) • iPhone 11 Pro (mobile) • 4FEAF225-103D-4237-96D7-026059D2BDB4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-7 (simulator) ! Doctor found issues in 3 categories. (base)
-
why I can't run my code where is the problem of this code?
void main() { const list = [1, 2, 3, 4]; final odd = where(list, (value) => value % 2 == 1); print(odd); } List<T> where<T>(List<T> items, bool Function(T) f) { var results = <T>[]; for (var item in items) { if (f(item)) { results.add(item); } } return results; }
this kind of error show in my terminal
lib/exercises/18-implement-where-function.dart:3:44: Error: The operator '%' isn't defined for the class 'Object?'.
- 'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '%' operator. final odd = where(list, (value) => value % 2 == 1);
void main() { const list = [1, 2, 3, 4]; final odd = where(list, (value) => value! % 2 == 1); print(odd); } List<T> where<T>(List<T> items, bool Function(T) f) { var results = <T>[]; for (var item in items) { if (f(item)) { results.add(item); } } return results; }
The operator '%' isn't defined for the type 'Object'. Try defining the operator '%'
-
Aligning image to center and button to bottom of the screen but image and button comes next to each other
What changes should I make to align button at bottom.
Buttons
class to displaybutton
widget is defined in another file.class Home extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( backgroundColor: Color(0xFFFFCCCC), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Image.asset( 'assets/images/TransperentBackgroundBlack.png', height: 250, ), Align( alignment:Alignment.bottomCenter, child:Buttons(), ), ], ), ), ); } }
-
Flutter StreamBuilder receives last item after every orientation change
Description:
I have a screen that has an error stream(all errors are being passed through that stream), if there were at least 1 error passed through that stream, it will be shown again after every orientation change. None of my stream related methods being triggered, the request is never made again, but somehow I am receiving the save old data error object in StreamBuilder builder.
Showcase video(a bit shaky but its the best I was able to record): https://drive.google.com/file/d/1BWPPxPmPjg1VXVtX0b6G6dOCq4qO2VZ4/view?usp=sharing
Here goes the refresh code:
Widget:
return NotificationListener<ScrollNotification>( onNotification: (ScrollNotification scrollInfo) { if (scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) { //_loadData(); return true; } return false; }, child: RefreshIndicator( onRefresh: () { return _mBlock.refreshSpots(); }, child: ListView.builder( itemCount: snapshot.data?.length ?? 0, itemBuilder: (context, position) { return SpotListItem(snapshot.data[position], () { Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) => SpoItemDetailsScreen( mSpotId: -1, ))); }); }, ), ));
Bloc method:
Future<List<SpotDto>> refreshSpots() { return handlePagingFuture(_reportsRepositoryImpl.getSpots(0), (data) { _mSpotList.clear(); addNewSpotsToList(data); }, _mBasePagingController, true); }
Base bloc future handling:
@protected Future<DataType> handlePagingFuture<DataType>( Stream<DataType> stream, Function(DataType data) function, BasePagingController<DataType> pagingController, bool isRefresh) { var completer = new Completer<DataType>(); pagingController.addLoadingLogic(stream).handleError((Object obj) { Fimber.e("handlePagingFuture"); handleError(obj, completer); }).listen((data) { function.call(data); refreshControllerIfNeeded(isRefresh, pagingController); completer.complete(); }); return completer.future; }
Actual error handling:
@protected handleError(Object errorObj, Completer completer) { Error<String> networkException; switch (errorObj.runtimeType) { case DioError: var dioError = (errorObj as DioError); Fimber.e((errorObj as DioError).type.toString()); Fimber.e((errorObj as DioError).error.toString()); switch (dioError.type) { case DioErrorType.CANCEL: networkException = Error("Canceled"); break; * * * default: var responseCode = dioError.response.statusCode; networkException = Error( "Received invalid status code: $responseCode", ); } break; } mErrorSink.add(networkException); break; default: if (errorObj is Exception) { mErrorSink.add(Error("qwe")); } else { mErrorSink.add(Error("qwe")); } } completer?.complete(); }
Any ideas how can I fix this?
-
How Can I Add phone call action to my ListTile in Flutter
I am writing a tool for community. My purpose is to give name surname and numbers in listtile and when people click on the names it dials assigned number. I tried url_launcher but I couldn't make it. Can check and tell me what is wrong with my code. This here is my code that I couldn't launch is there anything I miss?
import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:sarisayfav1/Gas.dart'; import 'package:sarisayfav1/Kargo.dart'; import 'package:sarisayfav1/Tamir.dart'; import 'package:url_launcher/url_launcher.dart'; import 'Book.dart'; import 'Food.dart'; class Arac extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Akcakale Sari Sayfa', theme: ThemeData( backgroundColor: Colors.black87, primaryColor: Colors.black, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: MyHomePage(title: 'Akçakale Sarı Sayfa'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( drawer: Drawer( child: ListView( // Important: Remove any padding from the ListView. padding: EdgeInsets.zero, children: <Widget>[ DrawerHeader( child: Text('Akçakale Sarı Sayfa Uygulaması', style: TextStyle(color: Colors.amberAccent, fontSize: 25)), decoration: BoxDecoration( color: Colors.black87, ), ), ListTile( leading: Icon(Icons.directions_bus), title: Text( 'Kargo Telefon Numaraları', ), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Kargo())); // Update the state of the app. // ... }, ), ListTile( leading: Icon(Icons.food_bank_outlined), title: Text( 'Lokanta-Yiyecek-İçecek', ), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Food())); // Update the state of the app. // ... }, ), ListTile( leading: Icon(Icons.menu_book_rounded), title: Text( 'Kırtasiye-Kitapçı', ), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Book())); // Update the state of the app. // ... }, ), ListTile( leading: Icon(Icons.local_gas_station), title: Text('Tüpçü-Sucu'), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Gas())); }, ), ListTile( leading: Icon(Icons.home_repair_service), title: Text( 'Elektrik-Su-Mobilya Tamircisi', ), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Tamir())); // Update the state of the app. // ... }, ), ListTile( leading: Icon(Icons.local_taxi), title: Text('Taşıma Hizmeti Sağlayan Özel Araç Sahipleri'), onTap: () { Navigator.push(context, new MaterialPageRoute(builder: (context) => new Arac())); }, ), ], ), ), appBar: AppBar( leading: Icon(Icons.settings), backgroundColor: Colors.black87, title: Text(widget.title, style: TextStyle(color: Colors.amberAccent)), ), body: ListTile( leading: Icon(Icons.person), dense: true, onTap: () => tel:+123456789, ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
-
How to create a stream and sink for List of objects using BLOC
I have a list of objects as:
[{name: "Rob", age: 20}, {name: "Bob", age: 30},]
How can I create a stream and sink for this?
I have searched everywhere but couldn't find any solution.
I know for a String or double or any other datatype, like this:
final _name = BehaviorSubject<String>(); Stream<String> get name => _name.stream; Function(String) get changeName => _name.sink.add;
Thanks in advance!!!
-
Flutter : Navigate with persistent side bar
I'm creating a flutter web project that looks like a dashboard. It has a side navigation and a body area that displays different screens.
To achieve this, I have divided my screen into two parts using Expanded and given them a flex value. And to display different screens I have used IndexedStack.
Here is my main.dart file :
import 'package:flutter/material.dart'; import 'package:xxx/screens/courses/courses_screen.dart'; import 'package:xxx/side_navigation/menu_item.dart'; import 'package:xxx/componnents/header.dart'; import 'package:websafe_svg/websafe_svg.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( visualDensity: VisualDensity.adaptivePlatformDensity, scaffoldBackgroundColor: Color(0xfffafafa), fontFamily: 'Poppins', ), home: MainScreenLayout(), ); } } class MainScreenLayout extends StatefulWidget { @override _MainScreenLayoutState createState() => _MainScreenLayoutState(); } class _MainScreenLayoutState extends State<MainScreenLayout> { int selectedIndex = 0; int hoverIndex = -1; Color bgColor = Colors.transparent; final List<MenuItem> menus = <MenuItem>[ MenuItem(label: 'Home', icon: Icons.home, screen: Container()), MenuItem(label: 'Courses', icon: Icons.add, screen: Container()), MenuItem(label: 'Students', icon: Icons.face_outlined, screen: Container()), MenuItem(label: 'Home', icon: Icons.home, screen: Container()), MenuItem(label: 'Courses', icon: Icons.add, screen: Container()), MenuItem(label: 'Students', icon: Icons.face_outlined, screen: Container()), ]; final List<Widget> _screens = [ Container( child: Image.asset( 'assets/try.png', width: 100, height: 100, ), ), CoursesScreen(), Container( child: WebsafeSvg.asset('assets/folder_icon.svg'), ), ]; void _changeBg(int index) { setState(() { hoverIndex = index; }); } void _resetBg() { setState(() { hoverIndex = -1; }); } @override Widget build(BuildContext context) { double _width = MediaQuery.of(context).size.width; return Scaffold( body: Row( children: [ Expanded( flex: 2, child: Container( decoration: BoxDecoration( color: Color(0xffffffff), borderRadius: BorderRadius.only( topRight: Radius.circular(_width * 0.03), bottomRight: Radius.circular(_width * 0.03), ), ), child: Column( children: <Widget>[ SizedBox( height: 50, ), Flexible( child: ListView.builder( itemCount: menus.length, itemBuilder: (BuildContext context, int index) { return MouseRegion( onHover: (event) { _changeBg(index); }, onExit: (event) { _resetBg(); }, child: MenuItemLayout( bgColor: hoverIndex == index ? Color(0xfffafafa) : Colors.transparent, menuItem: menus[index], isSelected: selectedIndex == index ? true : false, onTap: () { setState(() { selectedIndex = index; }); }, ), ); }, ), ), ], ), ), ), Expanded( flex: 7, child: Column( mainAxisSize: MainAxisSize.min, children: [ Header( label: menus[selectedIndex].label, ), Expanded( child: Container( child: IndexedStack( index: selectedIndex, children: _screens, ), ), ), ], ), ) ], ), ); } }
Here is the code for one of the screens (CourseScreen)
import 'package:flutter/material.dart'; import 'package:vjti_dashboard/componnents/responsive.dart'; import 'package:vjti_dashboard/screens/courses/courses_card.dart'; import 'package:vjti_dashboard/screens/courses/courses_model.dart'; class CoursesScreen extends StatelessWidget { final List<CoursesModel> allCourses = [ CoursesModel(courseId: '123', courseName: 'Ecommerce'), CoursesModel(courseId: '123', courseName: 'Big Data Analytics'), CoursesModel(courseId: '123', courseName: 'User Experience Design'), CoursesModel(courseId: '123', courseName: 'Technical Seminar'), CoursesModel(courseId: '123', courseName: 'Elective 1'), ]; @override Widget build(BuildContext context) { return ListView( scrollDirection: Axis.vertical, shrinkWrap: true, children: [ Sample( headingLabel: 'First Year', allCourses: allCourses, courseColor: Color(0xffEEF1E6), ), Sample( headingLabel: 'Second Year', allCourses: allCourses, courseColor: Color(0xffF9F1D6), ), Sample( headingLabel: 'Third Year', allCourses: allCourses, courseColor: Color(0xffE2F0CB), ), ], ); } } class Sample extends StatelessWidget { final String headingLabel; final Color courseColor; final List<CoursesModel> allCourses; const Sample({Key key, this.allCourses, this.headingLabel, this.courseColor}) : super(key: key); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 20), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[ GestureDetector( onTap: () {}, child: Container( padding: EdgeInsets.all(16), decoration: BoxDecoration( border: Border( bottom: BorderSide( color: Color(0xffd6d6d6), width: 1.0, ), ), ), child: Text(headingLabel), ), ), GridView.count( primary: false, physics: ScrollPhysics(), // to disable GridView's scrolling shrinkWrap: true, padding: const EdgeInsets.symmetric(vertical: 24, horizontal: 0), crossAxisSpacing: 20, childAspectRatio: 3 / 1, mainAxisSpacing: 20, crossAxisCount: Responsive.isDesktop(context) ? 4 : Responsive.isTablet(context) ? 3 : 2, children: List.generate( allCourses.length, (index) { return CourseCard( coursesModel: allCourses[index], containerColor: courseColor, ); }, ), ), ], ), ); } }
The side navigation works as it should and different pages are loaded while the navigation sticks to the left. When I click on any widget on the CourseScreen, I want to open another screen that would replace CourseScreen but the navigation should still be there.
How can I achieve this?
Note : I'm new to flutter and most of the code that I have written is not perfect and probably is not a good way. I would appreciate if you can point out bad codes in the above files.
Thank You!!!
-
How to change DropdownButton selected option color?
I have a DropdownButton in Flutter and i want to change the color of the selected option (see image). Default color is grey. I could not find a parameter of DropdownButton to change that. I tried
selectedRowColor
in ThemeData but it does not affect that color. Is it possible to change that color?Minimal reproducible example:
import 'package:flutter/material.dart'; main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( highlightColor: Colors.red, ), home: MyHome(), ); } } class MyHome extends StatefulWidget { @override State<StatefulWidget> createState() => _MyHomeState(); } class _MyHomeState extends State<MyHome> { List<String> options = ['A', 'B', 'C', 'D']; String selectedOption; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: DropdownButton( hint: Text('Please choose an option'), value: selectedOption, onChanged: (String newValue) { setState(() { selectedOption = newValue; }); }, items: options.map((option) { return DropdownMenuItem( child: Text(option), value: option, ); }).toList(), ), ), ); } }
-
What is the alternative of using setState() in flutter?
I am implementing Curved_Navigation_Bar in my Flutter poject and I am not using any class(i.e. Stateful / Stateless). I want to change the state of the icons that are in my curved_navigation_bar, means I want that animation effect on my navigation bar. Because the respective pages of those icons are navigating but not those items. No matter on which icon I click, it is still showing that first icon only. The animation/interpolation of icons is not happening.
As I am not using any Stateful/Stateless class, so I am not using Scaffold. Inside Scaffold we can change the state of the current object using setState(() { }).
So how can I change the state of my navigation bar?
Here is my code below:
navigation_bar.dart
import 'package:flutter/material.dart'; import 'package:curved_navigation_bar/curved_navigation_bar.dart'; import 'package:thehelpdesk/components/home/history.dart'; import 'package:thehelpdesk/components/home/home.dart'; import 'package:thehelpdesk/components/home/menu.dart'; import 'package:thehelpdesk/components/home/notification.dart'; import 'package:thehelpdesk/components/home/person.dart'; int currentIndex = 0 ; Widget navBarSection(Color color, Color btnColor, BuildContext context) { return CurvedNavigationBar( index: 0, items: [ Icon(Icons.home, color: Colors.white), Icon(Icons.notifications, color: Colors.white), Icon(Icons.menu, color: Colors.white), Icon(Icons.history, color: Colors.white), Icon(Icons.person, color: Colors.white), ], color: color, buttonBackgroundColor: btnColor, animationCurve: Curves.easeInCubic, animationDuration: Duration(milliseconds: 600), onTap: (index) { if(currentIndex == 0){ Navigator.of(context).push(MaterialPageRoute(builder: (context) => HomePage())); currentIndex = index ; } if(currentIndex == 1){ Navigator.of(context).push(MaterialPageRoute(builder: (context) => NotificationPage())); currentIndex = index ; } if(currentIndex == 2){ Navigator.of(context).push(MaterialPageRoute(builder: (context) => MenuPage())); currentIndex = index ; } if(currentIndex == 3){ Navigator.of(context).push(MaterialPageRoute(builder: (context) => HistoryPage())); currentIndex = index ; } if(currentIndex == 4){ Navigator.of(context).push(MaterialPageRoute(builder: (context) => PersonPage())); currentIndex = index ; } } );
One of the pages I want to navigate on tapping a icon:
home.dart
import 'package:flutter/material.dart'; import 'package:thehelpdesk/widgets/appbar.dart'; import 'package:thehelpdesk/widgets/navigation_bar.dart'; class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: aapBarSection('Home', Colors.blueAccent[700], context), bottomNavigationBar: navBarSection( Colors.blueAccent[700], Colors.blueAccent[700], context ), ); } }
Another page on tapping the 2nd icon:
notification.dart
import 'package:flutter/material.dart'; import 'package:thehelpdesk/widgets/appbar.dart'; import 'package:thehelpdesk/widgets/navigation_bar.dart'; class NotificationPage extends StatefulWidget { @override _NotificationPageState createState() => _NotificationPageState(); } class _NotificationPageState extends State<NotificationPage> { final message = [ 'Hi Xyz,your invoice for It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.', 'Hi Xyz, Agility Rehab Care wishing you a very happy birthday! for It has survived not only five centuries, but also the leap remaining essentially unchanged.', 'Hi Xyz, From our Agility Rehab Care you are being reminded that you have an appointment with us on this Friday.', 'Hi Xyz, This is a reminder for you from Agility Rehab Care It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.', ]; final images = [ 'assets/images/Invoice.png', 'assets/images/cake.png', 'assets/images/calender.png', 'assets/images/Reminder.png' ]; String date = '22/02/2021'; @override Widget build(BuildContext context) { return Scaffold( appBar: aapBarSection('Notification',Colors.blueAccent[700],context), bottomNavigationBar: navBarSection( Colors.blueAccent[700], Colors.blueAccent[700], context ), body: ListView.builder( itemCount: message.length, itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.fromLTRB(10, 10, 10, 10), child: SizedBox( height: 200, child: Card( elevation: 5.0, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), child: Padding( padding: const EdgeInsets.all(8.0), child: Container( child: Column( children: [ Flexible( flex: 7, child: Container( child: Row( children: [ Expanded( flex: 2, child: Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage( images[index]))), ), ), Expanded( flex: 8, child: Container( child: Text(message[index]), ), ), ], ), ), ), Flexible( flex: 3, child: Padding( padding: const EdgeInsets.fromLTRB(10, 10, 10, 10), child: Container( child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [Text(date)], ), ), ), ), ], ), ), )), ), ); }) ); } }
-
How to list objects from string list
Hello I have an app that have a lottery like system with a wheel of fortune kind of picking a winner,the problem i'm facing is the fortune spinner widget take items in the form of an object,i populate the wheel with names of user which i get from firebase so, what i want is to build the items object as the users name increase i have no idea of how to do it any help is deeply appreciated
This is the object class
class Luck{ final String image; final Color color; Luck(this.image, this.color); String get asset => "$image"; }
and this is the spinner widget
class FortuneSpinner extends StatefulWidget { final bool retVal; final List<Luck> items; FortuneSpinner({ @required this.retVal, this.items, }); @override State<StatefulWidget> createState() { return _FortuneSpinnerState(); } } class _FortuneSpinnerState extends State<FortuneSpinner> with SingleTickerProviderStateMixin { double _angle = 0; double _current = 0; AnimationController _ctrl; Animation _ani; static var _random = new Random(); static var _diceface = _random.nextInt(7) + 0; List<Luck> _items = [ Luck("apple", Colors.accents[_diceface]), Luck("raspberry", Colors.accents[_diceface + 2]), Luck("grapes", Colors.accents[_diceface + 4]), Luck("fruit", Colors.accents[_diceface + 6]), Luck("milk", Colors.accents[_diceface + 8]), Luck("salad", Colors.accents[_diceface + 1]), Luck("cheese", Colors.accents[_diceface + 3]), Luck("carrot", Colors.accents[_diceface + 5]), Luck("cheese", Colors.accents[_diceface + 7]), Luck("carrot", Colors.accents[_diceface + 2]), ]; @override void initState() { super.initState(); var _duration = Duration(milliseconds: 5000); _ctrl = AnimationController(vsync: this, duration: _duration); _ani = CurvedAnimation(parent: _ctrl, curve: Curves.fastLinearToSlowEaseIn); } @override dispose() { _ctrl.dispose(); // you need this super.dispose(); } @override Widget build(BuildContext context) { widget.retVal ? _animation() : Container(); return AnimatedBuilder( animation: _ani, builder: (context, child) { final _value = _ani.value; final _angle = _value * this._angle; return Stack( alignment: Alignment.center, children: <Widget>[ BoardView(items: widget.items, current: _current, angle: _angle), //_buildGo(), _buildResult( _value, ), ], ); }); } _buildGo() { ThemeManagment themeManagment = Provider.of<ThemeManagment>(context); return Material( color: themeManagment.theme == ThemeType.Dark ? Color(0xFF161A26) : Colors.blueGrey[20], shape: CircleBorder(), child: InkWell( customBorder: CircleBorder(), child: Container( alignment: Alignment.center, height: 72, width: 72, child: Text( "GO", style: TextStyle( fontSize: 22.0, fontWeight: FontWeight.bold, color: themeManagment.theme == ThemeType.Dark ? Colors.blueGrey[50] : Color(0xFF161A26), ), ), ), onTap: _animation, ), ); } _animation() { if (!_ctrl.isAnimating) { var _random = Random().nextDouble(); _angle = 20 + Random().nextInt(5) + _random; _ctrl.forward(from: 0.0).then((_) { _current = (_current + _random); _current = _current - _current ~/ 1; _ctrl.reset(); }); } } int _calIndex(value) { var _base = (2 * pi / widget.items.length / 2) / (2 * pi); return (((_base + value) % 1) * widget.items.length).floor(); } _buildResult(_value) { ThemeManagment themeManagment = Provider.of<ThemeManagment>(context); var _index = _calIndex(_value * _angle + _current); String _asset = widget.items[_index].asset; return Padding( padding: EdgeInsets.symmetric(vertical: 16), child: Column( children: [ Align( alignment: Alignment.topCenter, child: Text( _asset, style: TextStyle( color: themeManagment.theme == ThemeType.Dark ? Colors.blueGrey[50] : Color(0xFF161A26), ), ), ), ], ), ); } }
- Flutter Transition Widget from one parent to another